Recall & Review
beginner
What does it mean to set a specific bit in a number?
Setting a bit means changing that bit to 1, regardless of its current value.
Click to reveal answer
beginner
How do you clear a specific bit in a number?
Clearing a bit means changing that bit to 0, regardless of its current value.
Click to reveal answer
beginner
What does it mean to toggle a specific bit?
Toggling a bit means changing it from 0 to 1 or from 1 to 0, flipping its current value.
Click to reveal answer
intermediate
Which operator is used to set a bit at position
pos in C?The bitwise OR operator (|) with a mask:
num | (1 << pos) sets the bit at pos.Click to reveal answer
intermediate
How do you toggle a bit at position
pos in C?Use the bitwise XOR operator (^):
num ^ (1 << pos) flips the bit at pos.Click to reveal answer
Which operation sets the 3rd bit (0-based) of number
num in C?✗ Incorrect
Setting a bit uses OR (|) with a mask that has 1 at the bit position.
How do you clear the 2nd bit of
num?✗ Incorrect
Clearing a bit uses AND (&) with the negated mask ~(1 << pos).
What does
num ^ (1 << pos) do?✗ Incorrect
XOR (^) flips the bit at the given position.
If
num = 8 (1000 binary), what is num | (1 << 1)?✗ Incorrect
Setting bit 1 adds 2 to 8, resulting in 10 (1010 binary).
Which operator is used to clear a bit?
✗ Incorrect
Clearing uses AND with the negated mask to set the bit to 0.
Explain how to set, clear, and toggle a specific bit in a number using bitwise operators in C.
Think about how each operator affects bits: OR sets, AND clears, XOR flips.
You got /3 concepts.
Describe a real-life example where toggling a bit might be useful.
Imagine a light switch that can be flipped on or off.
You got /3 concepts.
