I'm using QDatastream to populate a quint32 array from a QByteArray on an Little-Endian ARM machine like below:
// Modify the header
QByteArray header = QByteArray::fromRawData((const char*)dataPtr,HEADER_SIZE);
QDataStream dataStream(header);
dataStream.setByteOrder(QDataStream::LittleEndian);
quint32 headerBuffer[NUMBER_HEADER_ENTRIES];
int bufferCnt = 0;
while ( !dataStream.atEnd() ) {
// Pop off a 32 bit int
quint32 temp;
dataStream >> temp;
// insert into buffer
headerBuffer[bufferCnt] = temp;
// Increment counter
bufferCnt++;
}
The problem is with byte order. I need to grab the last 4 bits of the 32bit field in headerBuffer[113], so I tried to AND that entry in headerBuffer with 0xf. The expected value to check against this field is "3". However, this AND operation gives me "a", as shown below. If I swap the bytes so that the entry is "0x1a13 & 0x000f", then I get "3". You can see below a few other examples of the values that are expected, versus what I am seeing. So, I am setting the ByteOrder of the QDataStream to LittleEndian, but still not getting the desired results. What am I doing wrong? How can I get 0x1a13 instead of 0x131a? Thanks!
qDebug() << "ONE: " << QString("%1").arg(headerBuffer[0], 0, 16); // This prints: 494d0152 -- Should be: 4d495201
qDebug() << "TWO: " << QString("%1").arg(headerBuffer[1], 0, 16); // This prints: 5400 -- Should be: 54
qDebug() << "THREE: " << QString("%1").arg(headerBuffer[113] & 0x000f, 0, 16); // This prints: a -- Should be: 3 ( headerBuffer[113] is always 0x131a )
qDebug() << "FOUR: " << QString("%1").arg(0x1a13 & 0x000f, 0, 16); // This prints: 3 -- Should be: 3