Browse Source

Fix missing trailing zeros while converting from decimal to binary

master
Abheek Dhawan 3 years ago
parent
commit
4ad1c4f36c
Signed by: abheekd GPG Key ID: 7BE81B8C14475B67
  1. 6
      converter.py

6
converter.py

@ -3,7 +3,7 @@ def decToBin(decIn):
ret = "" ret = ""
twoMult = int(1) twoMult = int(1)
currentTwoPwr = int(0) currentTwoPwr = int(0)
while ans != 0: while ans > 0:
''' '''
sleep(0.1) sleep(0.1)
print("TwoMult = " + str(twoMult)) print("TwoMult = " + str(twoMult))
@ -22,6 +22,10 @@ def decToBin(decIn):
currentTwoPwr -= 1 currentTwoPwr -= 1
twoMult = 2 ** currentTwoPwr twoMult = 2 ** currentTwoPwr
while (currentTwoPwr >= 0):
ret += "0"
currentTwoPwr -= 1
return int(ret) return int(ret)
def binToDec(binIn): def binToDec(binIn):

Loading…
Cancel
Save