Weil das nicht funktioniert
Liefert den falschen Wert!
Liegt daran das in dem Byte keine ascii zeichen(druckbaren) stehen(wenn ich das in anderen foren richtig gelesen hab)
Code: Alles auswählen
const QByteArray ba = m_logFile->read(4);
int size = ((static_cast<int>(ba[3]) & 0xFF)<<32)
+ ((static_cast<int>(ba[2]) & 0xFF) << 16)
+ ((static_cast< int>(ba[1]) & 0xFF) << 8)
+ ((static_cast<int>(ba[0]) & 0xFF) );
bool bOk = false;
qDebug() <<"toInt8"<< ba.toInt(&bOk, 8);
qDebug() <<"toInt16"<< ba.toInt(&bOk, 16);
qDebug() <<"toInt32"<< ba.toInt(&bOk, 32);
qDebug() <<"toInt0"<< ba.toInt(&bOk, 0);
qDebug() << "Shifted size is"<< size;
liefert
const QByteArray ba = m_logFile->read(4);
int size = ((static_cast<int>(ba[3]) & 0xFF)<<32)
+ ((static_cast<int>(ba[2]) & 0xFF) << 16)
+ ((static_cast< int>(ba[1]) & 0xFF) << 8)
+ ((static_cast<int>(ba[0]) & 0xFF) );
bool bOk = false;
qDebug() <<"toInt8"<< ba.toInt(&bOk, 8);
qDebug() <<"toInt16"<< ba.toInt(&bOk, 16);
qDebug() <<"toInt32"<< ba.toInt(&bOk, 32);
qDebug() <<"toInt0"<< ba.toInt(&bOk, 0);
qDebug() << "Shifted size is"<< size;
Zitat von qtforum.org
QByteArray also has toInt() method... but if I do array.toInt(&ok, 16) it will return 0 becuase, for example, 0x2A will be intepreted at some ascii value that's not between 1-9 or A-F... so it could not do the convertion. Note that I'm dealing will raw hex data here and not ascii. Am I missing something here?