Converting Char* hex to Integer..?
-
Hi~~ i have a string containing an hex number and i want to convert it to an integer. -------------------------------------------------------------- char *temp = "0x3e40"; i want to convert it to an interger.. which is 15936 how do i do that? Thanks
-
Hi~~ i have a string containing an hex number and i want to convert it to an integer. -------------------------------------------------------------- char *temp = "0x3e40"; i want to convert it to an interger.. which is 15936 how do i do that? Thanks
-
unsigned long nValue = 0;
long nConverted = sscanf (temp, "%x", &nValue);
if (nConverted != 1) {
failure;
}/ravi Let's put "civil" back in "civilization" Home | Articles | Freeware | Music ravib@ravib.com
Thanks :):):)
-
Hi~~ i have a string containing an hex number and i want to convert it to an integer. -------------------------------------------------------------- char *temp = "0x3e40"; i want to convert it to an interger.. which is 15936 how do i do that? Thanks
-
you could also use: char *temp = "0x3e40\0";
int iNum = atoi( temp )
// Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie -
Although atoi only converts base 10 numbers -
strtol (temp, NULL, 16)
would be correct for hex!Johnny ² wrote: Although atoi only converts base 10 numbers Thank you for pointing that out. I completely forgot about the fact that atoi works only with base 10 numbers. I am sorry for posting a message without testing the code first. // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie