質問

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.

役に立ちましたか?

解決

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top