要把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<<:setbase>
std::cout<<:setiosflags include iomanip>
还有一种采用c的做法:
printf(”%x\n”, i);
Qt呢QByteArray比较强大了,直接
.toHex();就将报文按16进制打印到屏幕上了
QByteArray接受16进制串口报文
把报文转换成看得懂的16进制字符.并以std::string保存这些字符串
QString(epc_num.toHex().data()).toLocal8Bit()
把std::string转成QString显示到界面上(实际就是将std::string --> QString)
p_qtable_widget_item->setText(QString::fromLocal8Bit(GLOBAL->radiophare_num.data()));
把字符转成数值,比如char[3]是字符'8',如何把他转成数值8?
uint32_t num = (uint32_t)*argv[4] - 0x30;