← Quiz: Bitwise Operators in C: all 15 questions
Quiz: Bitwise Operators in C · Question 14 of 15
Which expression flips (toggles) bit 2 of x, leaving the other bits unchanged?
Which expression flips (toggles) bit 2 of x, leaving the other bits unchanged?
- A.x | (1 << 2)
- B.x & ~(1 << 2)
- C.x ^ (1 << 2)
- D.x >> 2
Answer & explanation
Correct answer: x ^ (1 << 2)
XOR with 1 flips a bit and XOR with 0 keeps it; | sets the bit and & ~ clears it.
Can you get the rest right without peeking?
Take the timed Quiz: Bitwise Operators in C quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →