QT之大小端解析
1、小端模式的解析
QString str1 = "FEFE275FA70101DBB1010101010101010101010101010301010101010101010101010101011A"; QByteArray ba = QByteArray::fromHex(str1.toLatin1()); ushort hightCurrent = 0; // 类型可根据实际情况改变 memcpy(&hightCurrent, ba.data() + 3, sizeof(ushort));
2、大端的解析
QString str = "20030C416CB440D0B9"; QByteArray ba1 = QByteArray::fromHex(str.toLatin1()); //浮点型 float asd = 0; QByteArray big; big.resize(4); big[0] = ba1[6];big[1] = ba1[5];big[2] = ba1[4];big[3] = ba1[3]; memcpy(&asd, big.data(),sizeof(float)); //短整型 ushort my = (ushort)(ba1[3] << 8) + (uchar)ba1[4];