From 4ad1c4f36cae14d0c61e25a8904bdd597220545c Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Tue, 8 Feb 2022 21:10:56 -0600 Subject: [PATCH] Fix missing trailing zeros while converting from decimal to binary --- converter.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/converter.py b/converter.py index c0478c3..6d65912 100644 --- a/converter.py +++ b/converter.py @@ -3,7 +3,7 @@ def decToBin(decIn): ret = "" twoMult = int(1) currentTwoPwr = int(0) - while ans != 0: + while ans > 0: ''' sleep(0.1) print("TwoMult = " + str(twoMult)) @@ -22,6 +22,10 @@ def decToBin(decIn): currentTwoPwr -= 1 twoMult = 2 ** currentTwoPwr + while (currentTwoPwr >= 0): + ret += "0" + currentTwoPwr -= 1 + return int(ret) def binToDec(binIn):