十六进制数的转换
在编辑框中定义了一个字符串变量m_str,并赋值为m_str="12 3a 35 1f 4d 25 3b",想把它变成那个十六进制数再发送给接收方,请高手指点怎么进行转换,谢谢了!
接分........
void uti_unpack(unsigned char *pSrc, unsigned char * pDest, int len) { unsigned char ch1, ch2; for( int i = 0; i < len; i++ ) { ch1 = (pSrc[i] & 0xF0) >> 4; ch2 = pSrc[i] & 0x0F; ch1 += ( (ch1 > 9 ) ? 0x37 : 0x30 ); ch2 += ( (ch2 > 9 ) ? 0x37 : 0x30 ); pDest[i*2] = ch1; pDest[i*2 + 1] = ch2; } }
void uti_pack(unsigned char *pSrc, unsigned char *pDest, int len) { char ch1, ch2; for( int i = 0; i < (len / 2); i++ ) { ch1 = pSrc[i*2]; ch2 = pSrc[i*2 + 1]; (ch1 >= 'a' && ch1 <= 'z') ? (ch1 -= 32) : (ch1); (ch2 >= 'a' && ch2 <= 'z') ? (ch2 -= 32) : (ch2); ch1 -= ( (ch1 > '9' ) ? 0x37 : 0x30 ); ch2 -= ( (ch2 > '9' ) ? 0x37 : 0x30 ); pDest[i] = ( ch1 << 4 ) | ch2; } }