0

Number is a string == "0x1388" which is 5000 in dec. I'm not sure how to convert this hex string into the int value == 0x1388; Any help? And thanks in advance.

    value = strtol (number.c_str(),NULL, number.size());
user2904033
  • 133
  • 1
  • 3
  • 13

2 Answers2

0

The third argument is the base of the number you want to convert. In your case, the number is base 16 (hexadecimal), so you should pass 16 as the third argument. You can also pass 0, which will let the function determine the base from the prefix 0x.

Joseph Mansfield
  • 108,238
  • 20
  • 242
  • 324
0

Fix 3rd argument

value = strtol (number.c_str(),NULL, 16);
                                      ^^ Base of hexadecimal number
P0W
  • 46,614
  • 9
  • 72
  • 119