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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bitttttttttt13
    New Member
    • Aug 2010
    • 1

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

    how can i make a program that will convert from base 10 to base 2 to base 8 to base 16?
  • whodgson
    Contributor
    • Jan 2007
    • 542

    #2
    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)

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      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.

      Comment

      Working...