It never was hexadecimal to start with. You can use QString::number() as in my example, or QByteArray::toHex(), to display the value as a hexadecimal string.
To transfer the two bytes into a QByteArray in a little-endian byte ordering you could also use:
// No casting
qint16 value = -443; // OR quint16 value = 65093;
out.append(value & 0xFF);
out.append((value >> 8) & 0xFF);
qDebug() << out.toHex();
// OR
out.resize(sizeof(value)); // Must have the space already allocated
qToLittleEndian(value, reinterpret_cast<uchar *>(out.data()));
qDebug() << out.toHex();
// No casting
qint16 value = -443; // OR quint16 value = 65093;
QByteArray out;
out.append(value & 0xFF);
out.append((value >> 8) & 0xFF);
qDebug() << out.toHex();
// OR
out.resize(sizeof(value)); // Must have the space already allocated
qToLittleEndian(value, reinterpret_cast<uchar *>(out.data()));
qDebug() << out.toHex();
To copy to clipboard, switch view to plain text mode
You could do the original job without casting also:
qint16 value = in.at(1) << 8 | in.at(0);
qDebug
() << value <<
QString::number(value,
16);
QByteArray in("\x45\xfe", 2);
qint16 value = in.at(1) << 8 | in.at(0);
qDebug() << value << QString::number(value, 16);
To copy to clipboard, switch view to plain text mode
Bookmarks