typedef BYTE unsigned char;
</pre><pre code_snippet_id="1639451" snippet_file_name="blog_20160408_3_9633505" name="code" class="cpp">BYTE HexChar[256]={0};
void InitHexBuff()
{
HexChar[0] = '0';
HexChar[1] = '1';
HexChar[2] = '2';
HexChar[3] = '3';
HexChar[4] = '4';
HexChar[5] = '5';
HexChar[6] = '6';
HexChar[7] = '7';
HexChar[8] = '8';
HexChar[9] = '9';
HexChar[0xA] ='A';
HexChar[0xB] = 'B';
HexChar[0xC] = 'C';
HexChar[0xD] = 'D';
HexChar[0xE] = 'E';
HexChar[0xF] = 'F';
HexChar['0'] = 0;
HexChar['1'] = 1;
HexChar['2'] = 2;
HexChar['3'] = 3;
HexChar['4'] = 4;
HexChar['5'] = 5;
HexChar['6'] = 6;
HexChar['7'] = 7;
HexChar['8'] = 8;
HexChar['9'] = 9;
HexChar['A'] = 0xA;
HexChar['B'] = 0xB;
HexChar['C'] = 0xC;
HexChar['D'] = 0xD;
HexChar['E'] = 0xE;
HexChar['F'] = 0xF;
}
void Hex2Bin(char* hex,int len,BYTE* Outbuff)
{
for (int i = 0;i<len;i+=2)
{
BYTE a = hex[i];
BYTE b = hex[i+1];
Outbuff[i/2] = (HexChar[a] << 4)+HexChar[b];
}
}