Posted By

mouseroot on 10/17/10


Tagged


Versions (?)

2byte Hex String to int!


 / Published in: C++
 

Hex2Int("FF") returns 255 (if anyone has a better way todo this PLEASE let me know ;) )

  1. int Hex2Int(char i[])
  2. {
  3. int d=0;
  4. int a =0;
  5. char out[10];
  6. sscanf(i, "%02x", &a);
  7. sprintf(out, "%d",a);
  8. stringstream(out) >> d ;
  9. return d;
  10. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: leetNightshade on February 4, 2014

This isn't a great solution at all, and severely limited. If you're going to waste time writing your own solution only to use a stringstream, you should just use this: http://stackoverflow.com/a/1070499/353094

You need to login to post a comment.