I have a situation where I need to convert a hex string
// str contains "0x8aaaf200"
uint32_t var = (uint32_t)strtol(str, NULL, 0);
printf("conversion: %x \n\n", var); // prints 8aaaf200
You are actually getting LONG_MAX (which is 2147483647 or 0x7FFFFFFF) as return value, which happens when the value passed to strtol is greater than LONG_MAX. You should use the unsigned type to represent that number on your machine. Please use function strtoul() in place of strtol.