How do i convert string like 0x0000 to integer??? This code does not work(Func atof always return 0).
String str = "0xffff";
(unsigned int)atof(str);
How do i convert string like 0x0000 to integer??? This code does not work(Func atof always return 0).
String str = "0xffff";
(unsigned int)atof(str);
In addition to C++ std::stoi
, you can use strtol
(or strtoul
for unsigned) which works for C and C++:
int i = strtol(str, NULL, 0);
Last parameter 0 means auto-select base to be 8, 10 or 16, depending on how string looks like. For 0x
prefix, base 16 would be used. For 0
prefix, base 8 would be used. For other decimals, base 10 is tried.
Assuming String
is std::string
, you can use std::stoi:
std::string str("0xffff", 0, 0);
int i = std::stoi(str);