if(dat >= 0x30 && dat <= 0x39)
{
return (dat - 0x30);
}else if(dat >= 0x41 && dat <= 0x46)
OK, so you are comparing an incoming digit to be in the range 0 to 9, or A to F?
And you don't think this is more readable? When it mentions 0-9 and A-F and not some hex equivalent?
if(dat >= '0' && dat <= '9')
{
return (dat - '0');
}else if(dat >= 'A' && dat <= 'F')
Oh well, whatever works for you I guess.
I relatively, or with a bit of maths, know the value used.
With my method you don't need the maths.