Complete the code to set the 3rd bit of the variable 'flags'.
flags = flags [1] (1 << 2);
Using the bitwise OR operator | sets the specific bit without changing others.
Complete the code to clear the 1st bit of the variable 'flags'.
flags = flags [1] ~(1 << 0);
Using bitwise AND & with the negated bit mask clears the bit.
Fix the error in the code to toggle the 2nd bit of 'flags'.
flags = flags [1] (1 << 1);
Bitwise XOR ^ toggles the bit: if it was 1, it becomes 0; if 0, it becomes 1.
Fill both blanks to check if the 4th bit of 'flags' is set.
if ((flags [1] (1 << 3)) [2] 0) { // bit is set }
Use bitwise AND & to isolate the bit, then check if result is not equal != to zero.
Fill all three blanks to create a mask for bits 0 to 3 and clear them in 'flags'.
mask = (1 [1] 4) - 1; flags = flags [2] [3]mask; // bits 0-3 cleared
Shift 1 left by 4 to get 16, subtract 1 to get mask 0b1111. Then clear bits by AND with negated mask.
