I found this just now:
int hexToChar(char c)
{
char hexToCharResult = '\0';
if(c=='0')
hexToCharResult = 0;
else if(c=='1')
hexToCharResult = 1;
else if(c=='2')
hexToCharResult = 2;
else if(c=='3')
hexToCharResult = 3;
else if(c=='4')
hexToCharResult = 4;
else if(c=='5')
hexToCharResult = 5;
else if(c=='6')
hexToCharResult = 6;
else if(c=='7')
hexToCharResult = 7;
else if(c=='8')
hexToCharResult = 8;
else if(c=='9')
hexToCharResult = 9;
else if(c=='A')
hexToCharResult = 10;
else if(c=='B')
hexToCharResult = 11;
else if(c=='C')
hexToCharResult = 12;
else if(c=='D')
hexToCharResult = 13;
else if(c=='E')
hexToCharResult = 14;
else if(c=='F')
hexToCharResult = 15;
return hexToCharResult;
}
"Working" software has only unobserved bugs. (Parroty Error: Pieces of Nine! Pieces of Nine!)
Seriously: If you value it, take/fetch it yourself
Comments
Seriously: If you value it, take/fetch it yourself
Seriously: If you value it, take/fetch it yourself
Seriously: If you value it, take/fetch it yourself
actually he's not .. my bad - not coded C for a long time
int HexCharToInt (char c)
{
int result = 0;
if ((c >= '0') && (c <= '9'))
{
result = c - '0'; // numeric
}
else
{
c &= 0xbf; // to upper, if alpha
if ((c >= 'A') && (c <= 'F'))
{
result = c - 'A' + 10; // hexchar
}
}
return(result);
}
other trickery might get you tighter code, but this is efficient enough, copes with upper and lower case, and is quite perspicuous about its purpose and method.
but in context, I think he's calling it per character in a string. so why not pass the string address into the library routine atol ?
Seriously: If you value it, take/fetch it yourself
Strictly speaking I'm not sure there's a standard C function that does this (character, not string). There's a very quick cheat if you can guarantee ASCII, though you lose a bit of elegance if you properly generalise it and check inputs. Bizarre way to initialise the result all things considered.
(Edit, A-F aren't guaranteed contiguous... though it'd be an evil character set that broke that.)
If I understand your question, the answer is no because the space you're decoding from is not contiguous. The number by which you nobble depends on the range of characters you're nobbling from.
Seriously: If you value it, take/fetch it yourself
Seriously: If you value it, take/fetch it yourself
:-??
Seriously: If you value it, take/fetch it yourself