Hex2Bin

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,LPBYTE 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];
              }
}VS如何查看宏展开


你可能感兴趣的:(Hex2Bin)