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.
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.
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.
Base Conversion One algorithm for converting a base 10 number to another base b involves repeatedly...
Base Conversion One algorithm for converting a base 10 number to another base b involves repeatedly dividing by b. Each time a division is performed the remainder and quotient are saved. At each step, the dividend is the quotient from the preceding step; the divisor is always b. The algorithm stops when the quotient is 0. The number in the new base is the sequence of remainders in reverse order (the last one computed goes first; the first one goes...
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will...
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will implement Queue Abstract Data Type with the following functions/methods.  Any build-in/pre-defined Queue function/library (e.g., java.util.Queue in Java) is NOT allowed to use in your code. push(Element):  insert the input Element (e.g., String or Integer in Java) to the end of the queue. pop(): remove the head element of the queue and print the head element on screen. count():  return the total number of elements in the queue...
Write the algorithm for this program using the C++ language (not python or java). The explanation...
Write the algorithm for this program using the C++ language (not python or java). The explanation needs to be at least 250 words. Explain everything throughly step by step. While there is a built-in pop_back function in the vector class, there is no built-in pop_front function. Suppose a program needs a pop_front function that will remove the first element from the vector. For example, if the original vector is [1, 2, 3, 4, 5], then after passing in this vector...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT