• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:


How do you write a function in C++ to convert hexadecimal numbers to decimal numbers?
  • 3
1 Solution
Assuming the hexadecimal number is a string, then you can do it like this:

char buffer[] = "FF";
int value;
sscanf(buffer,"%x", &value);

if its not a string, then let us know what it is.
or, as a function:

int HexToDecimal(const char* hexString)
    int value = 0;
    sscanf(hexString,"%x", &value);
    return value;

luluaAuthor Commented:
The hexadecimal number is a combination of characters and numbers. so then how would you convert a number like this 0x0064FDF0 or 1239AS83
Sorry for not responding before now, been away, but:

I presume the data type is a string.

(i.e. it is typed in from the keyboard or read from a file or something like that).  The method above should work in that case.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now