Complete the code to set the 3rd bit of number n.
n = 8 n = n | (1 << [1]) print(bin(n))
Bits are zero-indexed from the right. The 3rd bit means index 2, so shifting 1 by 2 sets the 3rd bit.
Complete the code to clear the 1st bit of number n.
n = 15 n = n & ~(1 << [1]) print(bin(n))
Clearing the 1st bit means clearing bit at index 0, so shift 1 by 0.
Fix the error in the code to toggle the 4th bit of number n.
n = 10 n = n ^ (1 << [1]) print(bin(n))
Toggling the 4th bit means toggling bit at index 3, so shift 1 by 3.
Fill both blanks to set and then clear the 2nd bit of number n.
n = 5 n = n | (1 << [1]) n = n & ~(1 << [2]) print(bin(n))
Setting and clearing the 2nd bit means bit index 1 for both operations.
Fill all three blanks to toggle the 1st bit, set the 3rd bit, and clear the 2nd bit of number n.
n = 0 n = n ^ (1 << [1]) n = n | (1 << [2]) n = n & ~(1 << [3]) print(bin(n))
Toggling 1st bit is index 0, setting 3rd bit is index 2, clearing 2nd bit is index 1.
