c++ - Qt hex representation of a negative 8bit int? -
However, I am looking for a QT solution. I'm looking for a way to convert an 8-bit negative int into a hex representation by example it would be better understood. Output is greater than 2 bytes. However, when I change it into unsigned, it works fine. The documentation says: typedef quint8 supported by Q type for unsigned char This type of 8-bit guarantee is available on all platforms. Type Type qint8 This type of 8-bit guarantee is guaranteed on all platforms supported by Q. Should not be unsigned, not able to deal with negative numbers? The problem is that Although you can use
qint8 width = - 100; QDebug () & lt; & Lt; Caststring :: Number (width, 16); // "ffffffffffff9c"
quint8 width = - 100; QDebug () & lt; & Lt; Caststring :: Number (width, 16); // "9C"
QString :: number
int or
uint Type There are no 8-bit integers versions, so these are kept in bigger integers in the whole. It works well with signed integers because the leading zeroes are removed.
QDataStream , this code for
operator
QByteArray buffer; QDataStream Stream (and Buffer, QIODevice :: WriteOnly); Qint8 width = - 100; Stream & lt; & Lt; Width; QDebug () & lt; & Lt; Buffer.toHex (); // Output: "9c"
Comments
Post a Comment