Frage

This might be a stupid question but I can't seem to find how to display a byte from a QByteArray as "01011000" for example.

War es hilfreich?

Lösung

That's because the function is not related to the scope of QByteArray, which is a simple byte container. Instead, you need to get the specific byte (as char) to print and show singles bits from it. For instance, try this (magic):

char myByte = myByteArray.at(0);

for (int i = 7; i >= 0; --i) {
    std::cout << ((myByte >> i) & 1);
}

Assuming that your machine has 8-bit bytes (which is not as a bold statement as it would have been 20 years ago).

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top