Complete the code to set the 3rd bit of the variable num.
num = num | (1 << [1]);
Bits are counted from 0, so the 3rd bit is at position 2. Shifting 1 by 2 sets the 3rd bit.
Complete the code to clear (set to 0) the 5th bit of num.
num = num & ~(1 << [1]);
The 5th bit is at position 4 (counting from 0). We shift 1 by 4 and then invert it to clear that bit.
Fix the error in the code to toggle the 1st bit of num.
num = num [1] (1 << 0);
The XOR operator (^) toggles bits. Using it with 1 shifted by 0 toggles the 1st bit.
Fill both blanks to check if the 4th bit of num is set (1).
if ((num [1] (1 << [2])) != 0) { // bit is set }
Use bitwise AND (&) with 1 shifted by 4 to check if the 4th bit is set.
Fill all three blanks to create a mask that keeps only the lower 3 bits of num.
mask = (1 << [1]) [2] 1; result = num [3] mask;
Shift 1 by 3, subtract 1 to get 0b0111 mask. Use AND to keep lower 3 bits.
