A_*********@hotmail.com wrote:
hey there,
I was able to read a char string containing only digits and convert it
to its int equivalent. however now I need to do the same thing with a
char string containing a hexadecimal number.
below is my clumsy attempt. I think I have most of the problem covered
but I am finding it somewhat difficult to convert the 'a' through 'f'
values correctly. any suggestions anyone has would be tremendously
appreciated.
I would probably use the ANSI C strtol function.
----------- test.cc --------------------------------
#include <iostream>
#include <cstdlib>
int main() {
char hex[] = "1000";
int i = static_cast<int>(strtol(hex, NULL, 16));
std::cout << "i = " << i << '\n';
return 0;
}
----------------------------------------------------
Output is 4096 by the way.
--John Ratliff