[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

Hexadecimal Strings

How do I convert from a hexadecimal string to an integer???  I am using the g++ compiler under unix.
0
JOE_WIEMANN
Asked:
JOE_WIEMANN
  • 2
1 Solution
 
JOE_WIEMANNAuthor Commented:
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
     
0
 
mikeblasCommented:

The easy way:

int nInt;
sscanf(pstrYourString, "%x", &nInt);


..B ekiM
0
 
jkrCommented:
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!
0
 
JOE_WIEMANNAuthor Commented:
Thanks alot -- works wonders
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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