From 66d5924271bb48a7b5ca6a76dcb540eeeecd851f Mon Sep 17 00:00:00 2001 From: Yogesh Patil Date: Mon, 19 Oct 2020 21:21:05 +0530 Subject: [PATCH 1/2] Added BCD to Decimal --- mathgenerator/funcs/BCDtoDecimalFunc.py | 19 +++++++++++++++++++ mathgenerator/mathgen.py | 1 + 2 files changed, 20 insertions(+) create mode 100644 mathgenerator/funcs/BCDtoDecimalFunc.py diff --git a/mathgenerator/funcs/BCDtoDecimalFunc.py b/mathgenerator/funcs/BCDtoDecimalFunc.py new file mode 100644 index 0000000..7d93a57 --- /dev/null +++ b/mathgenerator/funcs/BCDtoDecimalFunc.py @@ -0,0 +1,19 @@ +from .__init__ import * + +def BCDtoDecimalFunc(maxNumber=10000): + n = random.randint(1000, maxNumber) + binstring = '' + while True: + q, r = divmod(n, 10) + nibble = bin(r).replace('0b', "") + while len(nibble) < 4: + nibble = '0' + nibble + binstring = nibble + binstring + if q == 0: + break + else: + n = q + + problem = "Integer of Binary Coded Decimal " + str(n) + " is = " + solution = int(binstring, 2) + return problem, solution \ No newline at end of file diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 9f570cc..d1f1d48 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -114,3 +114,4 @@ meanMedian=Generator("Mean and Median", 76,"Mean and median of given set of numb intMatrix22determinant = Generator("Determinant to 2x2 Matrix", 77, "Det([[a,b],[c,d]]) =", " a * d - b * c", determinantToMatrix22) compoundInterest = Generator("Compound Interest", 78, "Compound interest for a principle amount of p dollars, r% rate of interest and for a time period of t years with n times compounded annually is = ", "A dollars", compoundInterestFunc) decimalToHexadeci = Generator("Decimal to Hexadecimal", 79,"Binary of a=", "b", deciToHexaFunc) +BCDtoDecimal = Generator("Binary Coded Decimal to Integer", 80, "Integer of Binary Coded Decimal b is ", "n", BCDtoDecimalFunc) From 15ba021c21cce766e5769baa08630dd7895ef1f6 Mon Sep 17 00:00:00 2001 From: Luke Weiler Date: Wed, 21 Oct 2020 14:03:06 -0400 Subject: [PATCH 2/2] Update BCDtoDecimalFunc.py --- mathgenerator/funcs/BCDtoDecimalFunc.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mathgenerator/funcs/BCDtoDecimalFunc.py b/mathgenerator/funcs/BCDtoDecimalFunc.py index 7d93a57..33c0737 100644 --- a/mathgenerator/funcs/BCDtoDecimalFunc.py +++ b/mathgenerator/funcs/BCDtoDecimalFunc.py @@ -16,4 +16,6 @@ def BCDtoDecimalFunc(maxNumber=10000): problem = "Integer of Binary Coded Decimal " + str(n) + " is = " solution = int(binstring, 2) - return problem, solution \ No newline at end of file + return problem, solution + +bcd_to_decimal = Generator("Binary Coded Decimal to Integer", 91, "Integer of Binary Coded Decimal b is ", "n", BCDtoDecimalFunc)