Need to make int from hex representation string like "0xFA" or better "FA". Need something like atoi("FA"). Is there are any standard solutions for that?
Asked
Active
Viewed 9.2k times
39
vico
- 17,051
- 45
- 159
- 315
-
4Something like [`strtol`](http://en.cppreference.com/w/c/string/byte/strtol), you mean? – Jongware Dec 18 '13 at 09:42
-
3[Know your tools](http://en.cppreference.com/w/c) – user694733 Dec 18 '13 at 09:44
1 Answers
83
-
1Note: it also works with `0xFA`: "(optional) prefix (0x or 0X) indicating hexadecimal base (applies only when the base is 16 or 0)" – Jongware Dec 18 '13 at 09:44
-
28For unsigned, you should use strtoul() to properly handle strings like "0x81234567", otherwise you will get 0xFFFFFFFF returned. – gjcamann May 13 '14 at 15:56