|
The solution for example 10.2, on page 136-137 is incorrect. When variable a and b are 'A'-'F', the conversion should be:
a = a - 'A' + 10;
b = b - 'A' + 10;
And remember, it only converts uppercase hex values.
The complete function is then:
void TxtToHexFast (BYTE *pHex, char Txt[], int length)
{
int i, a, b;
for (i=0; i<length; i++)
{
a = (int)Txt[i*2];
b = (int)Txt[i*2+1];
if (a >= 'A')
a = a-'A'+10;
else
a = a-'0';
if (b >= 'A')
b = b-'A'+10;
else
b = b-'0';
pHex[i] = (BYTE)((a<<4) + b);
}
}
|