Added Decimal To BCD Function File

This commit is contained in:
Yogesh Patil
2020-10-22 09:15:07 +05:30
parent ab2008bc2a
commit f754987306

View File

@@ -0,0 +1,22 @@
from .__init__ import *
def DecimalToBCDFunc(maxNumber=10000):
n = random.randint(1000, maxNumber)
x=n
binstring = ''
bcdstring = ''
while x > 0:
nibble = x % 16
bcdstring = str(nibble) + bcdstring
x >>= 4
problem = "BCD of Decimal Number " + str(n) + " is = "
solution = int(bcdstring)
return problem, solution
decimal_to_bcd = Generator("Decimal to Binary Coded Decimal", 101,
"Binary Coded Decimal of Decimal n is ", "b",
DecimalToBCDFunc)
##for readme ## | 101 | Decimal to Binary Coded Decimal | Binary Coded Decimal of Decimal 34 is = | 22 | decimal_to_bcd |