C++ Hex to Decimal Conversion

I need to convert a hex number into decimal.  I'm using Visual Studio C++ 6.0 so it can be either C++ or C routine.  What should I use?  Is there a C++ routine available?
Who is Participating?
nixfreakConnect With a Mentor Commented:
I won't attempt to provide an answer as this looks like homework (not allowed on EE) and is very easy to solve anyway. But you might be interested to know that internally decimals, octals, and hexadecimal numbers are all stored in the same binary format. Checkout the output of this program:

#include <stdio.h>

int main() {
int i = 0xFE;    /* hexadecimal value */

printf("%d %x %o", i, i, i);    /* printout the value of i in decimal, hex and octal */
Infinity08Connect With a Mentor Commented:
If you want to convert a string representing a decimal number to an integer, then take a look at sscanf for C :


(especially the %x type specifier)

For C++, you could use a stringstream with the hex stream manipulator :


Note that those pages contain a complete reference, including examples.
All Courses

From novice to tech pro — start learning today.