Skip to content

Instantly share code, notes, and snippets.

@eguyd
Created June 22, 2019 21:20
Show Gist options
  • Save eguyd/a1d5a742dbb503770a8b9ef3d2e1e697 to your computer and use it in GitHub Desktop.
Save eguyd/a1d5a742dbb503770a8b9ef3d2e1e697 to your computer and use it in GitHub Desktop.
Convert Decimal to binary
decimal = int(input("ENTER A DECIMAL INT: "))
if decimal == 0:
print(0)
else:
print("QUOTIENT REMAINDER BINARY")
bitString = ""
while decimal > 0:
remainder = decimal % 2
decimal = decimal // 2
bitString = str(remainder) + bitString
print("%5d%8d%12s" % (decimal, remainder, bitString))
print("The binary representation is: ", bitString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment