Added BCD to Decimal

This commit is contained in:
Yogesh Patil
2020-10-19 21:21:05 +05:30
parent 8cbbfd1207
commit 66d5924271
2 changed files with 20 additions and 0 deletions

View File

@@ -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

View File

@@ -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)