typedef unsigned char byte;
typedef wchar_t charw;
typedef const charw ccharw;
ccharw *CharHexL (L"0123456789abcdef");
byte HexToByte( charw C )
{
C = towlower(C);
if( C >= CharHexL[ 0] && C <= CharHexL[ 9] ) return( byte(C-CharHexL[ 0]) );
if( C >= CharHexL[10] && C <= CharHexL[15] ) return( byte(C-CharHexL[10]) + 10 );
return(0);
}
inline byte HexToByte( charw C1, charw C2 )
{
return( (HexToByte(C1)<<4) + HexToByte(C2) );
}
If the string has an odd number of characters pass the first char to HexToByte(C) to get the values for the first byte. Walk the rest of the string two characters at a time using HexToByte(C1, C2) to convert the pairs to bytes.
...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack