From f7549873064114a35d1e35d67dd8643e8adf0987 Mon Sep 17 00:00:00 2001 From: Yogesh Patil Date: Thu, 22 Oct 2020 09:15:07 +0530 Subject: [PATCH] Added Decimal To BCD Function File --- mathgenerator/funcs/decimal_to_bcd.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 mathgenerator/funcs/decimal_to_bcd.py diff --git a/mathgenerator/funcs/decimal_to_bcd.py b/mathgenerator/funcs/decimal_to_bcd.py new file mode 100644 index 0000000..f9b235c --- /dev/null +++ b/mathgenerator/funcs/decimal_to_bcd.py @@ -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 |