Manipulating bits in bytes/ints etc. is generic C/C++, not something you need Qt for. It is done with the bitwise OR (|), AND (&) and XOR (^) operators:
unsigned char byte;
byte = 0; // set all the bits
byte |= 1; // set LSB (bit 0)
byte |= 128 ; // set MSB (bit 7)
byte |= 1 << 2 ; // set bit 2
byte |= 8 | 16; // set some more bits
byte &= ~4; // unset bit 2
byte &= ~(8 | 16); // unset some more bits
byte ^= 64; // toggle bit 6
byte ^= 64; // toggle bit 6 back again
unsigned char byte;
byte = 0; // set all the bits
byte |= 1; // set LSB (bit 0)
byte |= 128 ; // set MSB (bit 7)
byte |= 1 << 2 ; // set bit 2
byte |= 8 | 16; // set some more bits
byte &= ~4; // unset bit 2
byte &= ~(8 | 16); // unset some more bits
byte ^= 64; // toggle bit 6
byte ^= 64; // toggle bit 6 back again
To copy to clipboard, switch view to plain text mode
Bookmarks