Link to home
Start Free TrialLog in
Avatar of abayyari
abayyari

asked on

Convert Hex to decimal in C/C++?

Can anyone provide me with a function that would convert a hex value to decimal in C/C++?

The following function converts from decimal to Hex:
string outputashex(unsigned long l) {
     char buffer[1024];
     itoa(l, buffer, 16);
     return buffer;
}

I need from hex to decimal.
Thanks a lot.

Ahmed
Avatar of akshayxx
akshayxx
Flag of United States of America image

  #include <stdlib.h>
            unsigned long strtoul(const char *S, char **PTR,
                int BASE);

            unsigned long _strtoul_r(void *REENT, const char *S,
                char **PTR, int BASE);

for more information see manual pageof strtoul
ASKER CERTIFIED SOLUTION
Avatar of Tommy Braas
Tommy Braas
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mafalda
Mafalda

char hex_to_char(unsigned int i)
{
  char c = i % 256;
  return c;
}