# converting numbers from one base to another

• 10-03-2001
partnole
converting numbers from one base to another
Hello, I need help to write a progam which converts any base number to any other base.
For example: if the input base is 2 and the value is 10000110, then the value in base 10 136, and if the input base is 16 and the value is FF, then the value in base 2 is 11111111.
Thank you, as all help will be appreciated.
• 10-03-2001
zen
Post what you've come up with so far.
• 10-03-2001
Nick
The typical way is to divide and find the remainder, so like
to convert 15 in base 10 to base 2

and then putting the values of the ramainder together
15/2 = 7R1
7/2 = 3R1
3/2 = 1R1
1/2 = 0R1

1111
• 10-03-2001
The V.
Well, does this have to work with arbitrary bases? Because you can natively read and write ints in hex, decimal, or octal representations. Anything else, you'd need to code yourself.
• 10-04-2001
guest
you will also need to assign symbols to represent values greater than 9 if base is greater than 10. Also the values of the digits in any base other than 10 need to be stored as char not as int, especially if base is > 10. But that's probably obvious.