字符串字符显示与16进制显示之间的相互转换函数
字符串字符显示与16进制显示之间的相互转换.
四个有用的函数:
//Function to convert unsigned char to string of length 2
void CXXX::Char2Hex(unsigned char ch, char* szHex)
{
unsigned char byte;
byte[0] = ch/16;
byte[1] = ch%16;
for(int i=0; i {
if(byte[i] >= 0 && byte[i] szHex[i] = '0' + byte[i];
else
szHex[i] = 'A' + byte[i] - 10;
}
szHex[2] = 0;
}
//Function to convert string of length 2 to unsigned char
void CXXX::Hex2Char(char const* szHex, unsigned char& rch)
{
rch = 0;
for(int i=0; i {
if(*(szHex + i) >='0' && *(szHex + i) rch = (rch ='A' && *(szHex + i) rch = (rch
0条评论