Recall & Review
beginner
What does it mean to clear a specific bit in a register?
Clearing a bit means setting that bit to 0 while leaving other bits unchanged.
Click to reveal answer
beginner
Which bitwise operator is used to clear a specific bit in a register?
The bitwise AND operator (&) is used with the complement of a mask to clear a specific bit.
Click to reveal answer
intermediate
Given a register variable 'reg' and a bit position 'pos', write the expression to clear that bit.
reg = reg & ~(1U << pos); // This clears the bit at position 'pos' in 'reg'.
Click to reveal answer
intermediate
Why do we use the complement operator (~) when clearing a bit?
The complement operator creates a mask with all bits set to 1 except the bit to clear, which is 0. ANDing with this mask clears only that bit.
Click to reveal answer
beginner
What happens if you clear a bit that is already 0?
Nothing changes; the bit remains 0 and other bits are unaffected.
Click to reveal answer
Which operator is used to clear a specific bit in a register?
✗ Incorrect
Clearing a bit uses AND with the complement mask to set that bit to 0.
What does the expression (1 << pos) do?
✗ Incorrect
It shifts 1 left by 'pos' places, creating a mask with only that bit set.
What is the purpose of using ~ (bitwise NOT) in clearing a bit?
✗ Incorrect
The NOT operator flips bits so the target bit becomes 0, allowing AND to clear it.
If reg = 0b1111 and you clear bit 2, what is the new value of reg?
✗ Incorrect
Clearing bit 2 (counting from 0) changes 0b1111 to 0b1011.
What happens if you clear a bit that is already 0?
✗ Incorrect
Clearing a bit that is already 0 does not change the register.
Explain how to clear a specific bit in a register using bitwise operations.
Think about how to keep all bits except the one you want to clear.
You got /4 concepts.
Write a C code snippet to clear bit 5 of a variable named 'status'.
Use shift and complement operators with AND.
You got /1 concepts.