Python program.
Write a python program that can convert any radix-d (arbitrary base) number to the equivalent radix-e (another arbitrary base) number. Where e and d are members in [2, 16]:
Hints: The easiest approach is - you can convert the radix-d number to decimal one first, and then convert the decimal number to the radix-e number.
n5=0 #global variable
def decimalToF(n2,f):
global n5#making global variable available here using global
keyword
if(n2 > 1):
# divide with integral result
# (discard remainder)
decimalToF(n2//f,f)
n5=n5*10+(n2%f) # find the value for base f
n=int(input("enter number "))
e=int(input("enter e index "))
f=int(input("enter f index "))
i,decimal = 0,0
while(n != 0): #convert base e into decimal with this loop
dec = n % 10
decimal = decimal + dec * pow(e, i)
n = n//10
i += 1
decimalToF(decimal,f)#calling function to convert from decimal to
base f with two arguments
print(n5)
OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.