• 3205阅读
  • 0回复

[讨论]一个奇怪的现象,求高手 [复制链接]

上一主题 下一主题
离线zcgba
 
只看楼主 倒序阅读 楼主  发表于: 2012-10-15
  1. #include <QtCore/QCoreApplication>
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include <string.h>
  5. #include <cstdlib>
  6. #include <QObject>
  7. #include <QString>
  8. #include <QDebug>
  9. int main(int argc, char *argv[])
  10. {
  11.     QCoreApplication a(argc, argv);{    
  12.       unsigned char d[8];
  13.       d[0] = 0xA0;
  14.       d[1] = 0x01;
  15.       d[2] = 0x1D;
  16.       d[3] = 0x2E;
  17.       d[4] = 0x3F;
  18.       d[5] = 0x4C;
  19.       d[6] = 0x00;
  20.       d[7] = 0x03;
  21.       QString str;
  22.       QString strFour;
  23.       quint64 intStr;
  24.       quint64 intStr11;
  25.       quint32 intStrOne;
  26.       quint16 intStrTwo;
  27.       intStr = d[7];
  28.       for (int i = 6; i >= 2; i--){
  29.           intStr = (intStr << 8)|d[i];
  30.       }
  31.      str = QString::number(intStr);
  32.      qDebug() << str;
  33.      intStrOne = d[7];
  34.      intStrOne = (intStrOne << 8) | d[6];
  35.      intStrOne = (intStrOne << 8) | d[5];
  36.      intStrOne = (intStrOne << 8) | d[4];
  37.      qDebug()<<intStrOne;
  38.      intStrTwo = d[3];
  39.      intStrTwo = (intStrTwo << 8) | d[2];
  40.      qDebug()<<intStrTwo;
  41.      intStr11 = (intStrOne << 16)|intStrTwo;
  42.      qDebug() << intStr11;
  43.      strFour = QString::number(intStr11);
  44.      qDebug()<<strFour;
  45.      return a.exec();
  46. }
我希望strFour 结果和str一样,但是结果却很奇怪,然后把quint32 intStrOne; 改成quint64 intStrOne; 结果就对了,为什么,求高手解答,因为我明明intStrOne 是4个字节。
快速回复
限100 字节
 
上一个 下一个