1. 程式人生 > >CString的16進位制轉換成BYTE陣列

CString的16進位制轉換成BYTE陣列

BYTE CSingleDlg::CStringHex2Byte( BYTE * byBuffer, CString strInput )
{
int nLen = strInput.GetLength();
BYTE byTemp = 0x00;
for ( int i=0, j = 0; i < 1024, j < nLen; i++,j++)
{
if( strInput[j] == '\0')
return 0;
if( strInput[j] == ' ')
++j;
byTemp = strInput[j];
byBuffer[i] = Hex2Char( byTemp )<<4;//左移4位
if( strInput[j+1] == '\0')
return 0;
if(  strInput[++j] == ' ' )
++j;
byTemp = strInput[j];
byBuffer[i] = byBuffer[i] + (Hex2Char( byTemp ) & 0xF);//取低四位相加
}
return 0;
}