Skip to content

Instantly share code, notes, and snippets.

@marcogravbrot
Created August 23, 2019 23:46
Show Gist options
  • Save marcogravbrot/3c6093f26ed7e1dbacf076410f8a5ba7 to your computer and use it in GitHub Desktop.
Save marcogravbrot/3c6093f26ed7e1dbacf076410f8a5ba7 to your computer and use it in GitHub Desktop.
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