要把uchar中的数值打印出来,以16进制形式打印出来这样才好阅读
unsigned char dlgram[] = {0x01, 0x10, 0x45, 0x06, 0x02, 0x00, 0x04, 0xe9, 0x10, 0x20, 0x9e };
std::cout << std::hex << (int)dlgram[0] << " “<< (int)dlgram[1] << std::endl;
uint16_t result = crc16(dlgram, 11);
uint8_t hibyte = (result >> 8) & 0x00ff;
uint8_t lobyte = result & 0x00ff;
std::cout << “lobyte: " << std::hex << (int)lobyte << std::endl;
std::cout << "hibyte: " << std::hex << (int)hibyte << std::endl;
std::cout << "result: " << std::hex << result << std::endl;
以上亲测可用
这篇博客提到另外几种方法https://blog.csdn.net/feng125452/article/details/32910689
int i = 23;
std::cout<<std::setbase(16)<<std::endl;
std::cout<<std::setiosflags(std::ios::hex)<<i<<std::endl; //need include iomanip
还有一种采用c的做法:
printf(”%x\n”, i);
Qt呢QByteArray比较强大了,直接
.toHex();就将报文按16进制打印到屏幕上了