測試環境:mfc 2019
使用方式
unsigned char buff[2] = { '9','E' };
unsigned char ucResult = '0';
ucResult = catChar2Hex(buff[0], buff[1]);
CString cst;
cst.Format(L"%x", int(ucResult));
MessageBox(cst);
結果: 0x9E
參考:https://blog.csdn.net/yhxxhy978/article/details/94136796
unsigned char catChar2Hex(unsigned char hByte, unsigned char lByte)
{
unsigned char ucTmp = 0x00;
unsigned char high, low;
if (hByte >= 'A' && hByte <= 'F')
high = hByte - 'A' + 10;
else if (hByte >= 'a' && hByte <= 'f')
high = hByte - 'a' + 10;
else if (hByte >= '0' && hByte <= '9')
high = hByte - '0';
else
ucTmp = 0xff;
if (lByte >= 'A' && lByte <= 'F')
low = lByte - 'A' + 10;
else if (lByte >= 'a' && lByte <= 'f')
low = lByte - 'a' + 10;
else if (lByte >= '0' && lByte <= '9')
low = lByte - '0';
else
ucTmp = 0xff;
ucTmp = (high << 4) | (low << 0);
return ucTmp;
}
沒有留言:
張貼留言