Link to home
Start Free TrialLog in
Avatar of JOE_WIEMANN
JOE_WIEMANN

asked on

Hexadecimal Strings

How do I convert from a hexadecimal string to an integer???  I am using the g++ compiler under unix.
Avatar of JOE_WIEMANN
JOE_WIEMANN

ASKER

For example: FF = 255
              F = 15
              E = 14
              D = 13
              C = 12
              B = 11
              A = 10
              9 = 9
              8 = 8
              7 = 7
              6 = 6
              5 = 5
              4 = 4
              3 = 3
              2 = 2
              1 = 1
              0 = 0
     
ASKER CERTIFIED SOLUTION
Avatar of mikeblas
mikeblas

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 jkr
Or, use 'strtol()':

#include <stdlib.h>

char* pcHex ="0xff";
char* pcCnvEnd;
int   n;

  n = (int) strtol ( pszHex, &pcCnvEnd, 16); // <-- numeric base!!

Feel free to ask if you need more information!
Thanks alot -- works wonders