Question

Python program. Write a python program that can convert any radix-d (arbitrary base) number to the...

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.

Homework Answers

Answer #1

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:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program in java that: 1. takes any number in any base between 2 and...
Write a program in java that: 1. takes any number in any base between 2 and 16 and converts it to base 10. 2. converts base 10 numbers to any given base between 2 & 16. The program should have a gui with an input box and two buttons, one button to convert any base between 2 and 16 to base 10; and one button to convert base 10 to any base between 2 and 16. **Please DO NOT upload...
Write a Java program named BinaryConversion that will convert base 2 numbers to base 10 numbers....
Write a Java program named BinaryConversion that will convert base 2 numbers to base 10 numbers. The data for this program will be entered from the keyboard using JOptionPane one 16-bit binary number at a time. Note that each base 2 number is actually read in as a String. The program should continue until a 16-bit base 2 number consisting of all 0’s is entered. Once the 16-bit number has been entered your program should make sure that the input...
In C++ Write a program that will convert a string of binary digits to their decimal...
In C++ Write a program that will convert a string of binary digits to their decimal equivalent. For convenience limit the binary number to 16 bits. Write the decimal equivalent to the screen. For this program you must read in the binary number as a string type. If you were to enter a large binary number like 110110001100111 as a decimal value it would be too large to fit in an int type.
Python Programming 4th Edition: - Write a program that test and display if a number enter...
Python Programming 4th Edition: - Write a program that test and display if a number enter is divisible by 2 and/or 3. Hints: - Use the correct operation - Prompt the user to enter a number The output should look like as follows - Enter an integer: --Number is divisible by 2 and 3 --Number is divisible by either 2 or 3, but not both --Number is not divisible by either 2 or 3
How to code this in python Write a program that computes and prints the first 1000...
How to code this in python Write a program that computes and prints the first 1000 prime numbers - simply write out each prime number on a new line. In implementing this solution I want you to define 2 functions: is_prime which can be used to test whether a number is a prime (e.g. is_prime(17) returns True but is_prime(9) returns False) and compute_primes which will return an array (or Python list) of the first n primes where n is passed...
Write a python program that can calculate the total number of letters entered in a collection...
Write a python program that can calculate the total number of letters entered in a collection of words. The program must ask the user for input until the user either types “quit” or “X” in upper or lower case. The number of letters in each word is displayed and the total of all letters in all words (excluding quit or X) is displayed at the end.
Write a program in python that prints the count of all prime numbers between A and...
Write a program in python that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = The 5 digit unique number you had picked at the beginning of the semester B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2,...
PYTHON 3 Write a program that prints the count of all prime numbers between A and...
PYTHON 3 Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = 21212 B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and 29. Rules: You should first...
Convert the decimal number 147 base 10 to base 3. However, do this using a POWER...
Convert the decimal number 147 base 10 to base 3. However, do this using a POWER SERIES EXPANSION of the form 147_10=a_2 *R^2+a_1*R^1+a_0*R^0, where R is the number 10 in the base of the number you want to convert to (3) (i.e., R=10_3) and {a_0, a_1,a_2} are the coefficients represented in base 3. Verify your answer using the "division method". Show all your work and all steps.
PYTHON Exercise 5. Guess the number 1. Develop a “Guess the number” game. Write a program...
PYTHON Exercise 5. Guess the number 1. Develop a “Guess the number” game. Write a program that comes up with a random number and the player has to guess it. The program output can be like this: I am thinking of a number between 1 and 20. Take a guess. 10 Your guess is too low. Take a guess. 15 Your guess is too low. Take a guess. 17 Your guess is too high. Take a guess. 16 Good job!...