Change your "s" variable line from. int s = atoi(substr);. to. int s = strtol(substr, NULL, 16); ...
stackoverflow.com