By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,640 Members | 2,355 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,640 IT Pros & Developers. It's quick & easy.

How to convert from base 10 to base 2 to base 8 to base 16

P: 1
how can i make a program that will convert from base 10 to base 2 to base 8 to base 16?
Aug 26 '10 #1
Share this Question
Share on Google+
2 Replies

P: 542
One way is to use the manipulators dec, hex and oct
There is no std bin manipulator as far as I know so you have to write those functions yourself.
However hex is easy to convert to bin and back. Take each hex character separately
and write the 4 bit bin equivalent.
e.g. 25b3 == 0010 0101 1011 0011 (the spaces are to make it easier to see)
Aug 26 '10 #2

Expert Mod 5K+
P: 9,197
Another way is to write a function with two arguments. One for the number to convert and one for the base.

Then just call this function when you need a conversion.

Like maybe a finance program that keeps all the amounts in pennies. Only when a report or display is need does the program need to display dollars and cents with a $ and a decimal point. So this program only needs to call the conversion function when an amount needs to be reported oir displayed.

This leaves a program free to keep data values in the most convenient form.
Aug 27 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.