Created
June 22, 2019 21:20
-
-
Save eguyd/a1d5a742dbb503770a8b9ef3d2e1e697 to your computer and use it in GitHub Desktop.
Convert Decimal to binary
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
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