Search code examples
c++ccharasciiqbytearray

QByteArray data format explanation


I am confused about QByteArray data. Can someone please explain the below scenario for me. enter image description here

Here data type for each array index is char. I understand some of those values. Like 74 'J' I understand the first one is ASCII and second one is the corresponding character. But what is the meaning of -1 '\\377'

Also what does the below gui means?? I sent the QByteArray of above to a function which takes the QByteArray as unsigned char* source. The below gui is showing the value of that source. enter image description here

The main confusing part is the first line's value 0x87089e8 "\377\330\377\340"


Solution

  • char in C/C++ is a signed 1-byte integer. This GUI is simply expressing that value as a signed decimal number, and the equivalent ASCII character.

    You're asking about the byte value -1, which can be interpretted in the following ways:

    Binary     11111111
    Octal      0377
    Hex        0xFF
    Decimal    -1    (Signed)
               255   (Unsigned)
    
    ASCII      \377
               \xFF
    

    Note that there isn't a standard printable ASCII character for 255, which is why they show it like they do.

    Another Example:

    Binary     01001010
    Octal      0112
    Hex        0x4A
    Decimal    74    (Signed)
               74   (Unsigned)
    ASCII      'J'