Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Binary, Octal, Hex and Decimal conversions??

Options
  • 17-04-2009 8:50am
    #1
    Registered Users Posts: 329 ✭✭


    Hey im studying c++ and was wondering how to convert from binary to hexadecimal to octal and vice versa. Just studying for test in a month and need serious help on the subject... Thanks..


Comments

  • Closed Accounts Posts: 5,096 ✭✭✭--amadeus--


    Have you had a chance to read teh charter?

    Try this as well.


  • Registered Users Posts: 5,379 ✭✭✭DublinDilbert


    Nappy wrote: »
    Hey im studying c++ and was wondering how to convert from binary to hexadecimal to octal and vice versa. Just studying for test in a month and need serious help on the subject... Thanks..

    From your question it is not clear what you want to do. Before you can do anything in programming you need to have it clear and express it in plain english.

    Do you want to convert an integer variable into a string representation of different bases (binary, hex & octal)? And convert a string representations of a number (with binary/hex/octal) back to an integer?

    There's various ways you can do this, are you supposed to code the conversion from scratch or use libraries?

    The binary conversion is very easy to do from scratch, with a for loop and some bit shifts.

    The hex conversion is easy enough too you can use the %x in a printf, or use std::hex in a cout statement. I think think you can also use std::hex in a cin or a buffered string also, to do the opposite conversion.


  • Registered Users Posts: 15,065 ✭✭✭✭Malice


    Nappy wrote: »
    Hey im studying c++ and was wondering how to convert from binary to hexadecimal to octal and vice versa. Just studying for test in a month and need serious help on the subject... Thanks..
    Did you try Google? Also I think you should have taken note of what the mod posted on your last thread.


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    There are probably APIs for doing it but the easy way if you had to write your own is to create a lookup table. Base 2 to Base 26. :D


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    :mad:


  • Advertisement
This discussion has been closed.
Advertisement