mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 06:25:23 +01:00
22 lines
562 B
Python
22 lines
562 B
Python
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", 103,
|
|
"Binary Coded Decimal of Decimal n is ", "b",
|
|
DecimalToBCDFunc)
|