Recall & Review
beginner Click to reveal answer
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.
beginner Click to reveal answer
How do you clear a specific bit in a number?
Clearing a bit means changing that bit to 0, regardless of its current value.
beginner Click to reveal answer
What does it mean to toggle a specific bit in a number?
Toggling a bit means flipping it: if it is 1, change it to 0; if it is 0, change it to 1.
intermediate Click to reveal answer
Which bitwise operator is used to set a bit?
The OR operator (|) is used to set a bit by OR-ing the number with a mask that has 1 at the target bit position.
beginner Click to reveal answer
How do you create a mask to target the nth bit for setting, clearing, or toggling?
Use (1 << n) to create a mask with only the nth bit set to 1, where n is the bit position starting from 0.
Which operation sets the 3rd bit of number x to 1 without changing other bits?
✗ Incorrect
Using OR with (1 << 3) sets the 3rd bit to 1.
How do you clear the 2nd bit of number x?
✗ Incorrect
AND with the negation of (1 << 2) clears the 2nd bit.
What does toggling the 1st bit of x do?
✗ Incorrect
XOR with (1 << 1) flips the 1st bit.
What is the mask to target the 5th bit (0-based) in a number?
✗ Incorrect
1 << 5 creates a mask with only the 5th bit set.
Which operator is used to toggle a bit?
✗ Incorrect
XOR (^) flips bits where the mask has 1.
Explain how to set, clear, and toggle a specific bit in a number using bitwise operators.
Think about how each operator affects bits when combined with a mask.
You got /4 concepts.
Describe how to create a mask for the nth bit and why it is important in bit manipulation.
Focus on how shifting 1 left by n positions targets the nth bit.
You got /4 concepts.
