This is a resume of most common bitwise operations in c/c++. Always useful to have in hand! Extracted from here: https://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit
Setting a bit
number |= 1 << n;
Clearing a bit
number &= ~(1 << n);
Toggling a bit
number ^= 1 << n;
Checking a bit
bit = (number >> n) & 1;
Changing the nth bit to x
number = (number & ~(1 << n)) | (x << n);
Leave a Reply