- #include <QtCore/QCoreApplication>
- #include <stdio.h>
- #include <iostream>
- #include <string.h>
- #include <cstdlib>
- #include <QObject>
- #include <QString>
- #include <QDebug>
- int main(int argc, char *argv[])
- {
- QCoreApplication a(argc, argv);{
- unsigned char d[8];
- d[0] = 0xA0;
- d[1] = 0x01;
- d[2] = 0x1D;
- d[3] = 0x2E;
- d[4] = 0x3F;
- d[5] = 0x4C;
- d[6] = 0x00;
- d[7] = 0x03;
- QString str;
- QString strFour;
- quint64 intStr;
- quint64 intStr11;
- quint32 intStrOne;
- quint16 intStrTwo;
- intStr = d[7];
- for (int i = 6; i >= 2; i--){
- intStr = (intStr << 8)|d[i];
- }
- str = QString::number(intStr);
- qDebug() << str;
- intStrOne = d[7];
- intStrOne = (intStrOne << 8) | d[6];
- intStrOne = (intStrOne << 8) | d[5];
- intStrOne = (intStrOne << 8) | d[4];
- qDebug()<<intStrOne;
- intStrTwo = d[3];
- intStrTwo = (intStrTwo << 8) | d[2];
- qDebug()<<intStrTwo;
- intStr11 = (intStrOne << 16)|intStrTwo;
- qDebug() << intStr11;
- strFour = QString::number(intStr11);
- qDebug()<<strFour;
- return a.exec();
- }
我希望strFour 结果和str一样,但是结果却很奇怪,然后把
quint32 intStrOne; 改成
quint64 intStrOne; 结果就对了,为什么,求高手解答,因为我明明intStrOne 是4个字节。