Reputation: 1217
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.
Upvotes: 0
Views: 2963
Reputation: 33046
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).
Upvotes: 1