I'm looking for the least amount of code in C, in order to convert a char to int, where it flags -1 (or any error flag) if the char is not a valid hex digit.
here's what I came up with, is there a shorter way?
// input example
char input = 'f';
// conversion segment
int x = input - '0';
if (!((x >= 49 && x <= 54) || (x >= 0 && x <= 9))) x = -1;
if (x > 9) x -= 39;
// test print
printf("%d", x);