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
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,
_
thanks, can you give an example how i can access to bits of an unsigned char variables by QBitArray class? is this code true?
Qt Code:
unsigned char un;To copy to clipboard, switch view to plain text mode
thanks fore more help
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.
Qt 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);To copy to clipboard, switch view to plain text mode
Last edited by ChrisW67; 27th December 2015 at 21:03.
Alex22 (28th December 2015)
Bookmarks