hi, there is a char variable. i need to access to the bits of that. i think i can do this by QBitArray class. please help me in this way. i searched this but saw no example.
thanks for any help
Printable View
hi, there is a char variable. i need to access to the bits of that. i think i can do this by QBitArray class. please help me in this way. i searched this but saw no example.
thanks for any help
You can also just use the bit maipulation operators, such as & and |
Cheers,
_
QBitArray is a device for managing an arbitrary length list of single-bit flags, not general bit manipulations. There is no obvious way to construct a QBitArray from a preexisting integer that does not involve solving the bit access problem manually first.
Code:
char c = 0xaa; // 1010 1010 for (int i = 0; i < 8; ++i) qDebug() << "Bit" << i << ":" << ((c >> i) & 0x01); char bit34 = (c & 0x18); // you may want to right shift these >> 3 // clear bits 3 and 4 c = (c & ~0x18); // set bits 3 and 4 c = (c | 0x18);