Created
August 23, 2019 23:46
-
-
Save marcogravbrot/3c6093f26ed7e1dbacf076410f8a5ba7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def decimalToBinary(tall): | |
index = [128, 64, 32, 16, 8, 4, 2, 1] | |
count = 0 | |
binary = "" | |
for x in range(len(index)): | |
total = count + index[x] | |
if (total <= tall): | |
count += index[x] | |
binary += "1" | |
else: | |
binary += "0" | |
return binary | |
print(decimalToBinary(21)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment