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.

  qint8 width = - 100; QDebug () & lt; & Lt; Caststring :: Number (width, 16); // "ffffffffffff9c"   

Output is greater than 2 bytes.

However, when I change it into unsigned, it works fine.

  quint8 width = - 100; QDebug () & lt; & Lt; Caststring :: Number (width, 16); // "9C"   

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 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.

Although you can use QDataStream , this code for operator provides type:

  QByteArray buffer; QDataStream Stream (and Buffer, QIODevice :: WriteOnly); Qint8 width = - 100; Stream & lt; & Lt; Width; QDebug () & lt; & Lt; Buffer.toHex (); // Output: "9c"    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -