Recall & Review
beginner
What does the AND (&) bitwise operator do between two bits?
The AND operator returns 1 only if both bits are 1; otherwise, it returns 0.<br>Example: 1 & 1 = 1, 1 & 0 = 0, 0 & 0 = 0.
Click to reveal answer
beginner
Explain the OR (|) bitwise operator with an example.
The OR operator returns 1 if at least one of the bits is 1; otherwise, it returns 0.<br>Example: 1 | 0 = 1, 0 | 0 = 0, 1 | 1 = 1.
Click to reveal answer
beginner
What is the result of XOR (^) between two bits?
XOR returns 1 if the bits are different, and 0 if they are the same.<br>Example: 1 ^ 0 = 1, 1 ^ 1 = 0, 0 ^ 0 = 0.
Click to reveal answer
intermediate
Describe the NOT (~) bitwise operator.
NOT flips each bit: 1 becomes 0, and 0 becomes 1.<br>Example: ~1 (in 1-bit) = 0, ~0 = 1.<br>In computers, it also changes the sign due to two's complement representation.
Click to reveal answer
intermediate
What happens when you perform a left shift (<<) and right shift (>>) on a binary number?
Left shift (<<) moves bits to the left, adding zeros on the right, effectively multiplying by 2 for each shift.<br>Right shift (>>) moves bits to the right, discarding bits on the right, effectively dividing by 2 for each shift.<br>Example: 4 (0100) << 1 = 8 (1000), 4 >> 1 = 2 (0010).
Click to reveal answer
What is the result of 5 & 3 in binary? (5 = 0101, 3 = 0011)
✗ Incorrect
AND compares bits: 0&0=0,1&1=1, so 0101 & 0011 = 0001 which is 1.
Which operator returns 1 only when bits are different?
✗ Incorrect
XOR returns 1 if bits differ, 0 if they are the same.
What does the expression ~0 evaluate to in a 4-bit system?
✗ Incorrect
NOT flips all bits: ~0000 = 1111, which is -1 in two's complement.
What is the decimal result of 6 << 2?
✗ Incorrect
Left shift by 2 multiplies by 2^2=4, so 6*4=24.
Which bitwise operator would you use to clear specific bits (set them to 0)?
✗ Incorrect
AND with a mask having 0s clears bits; 1s keep bits unchanged.
Explain how the XOR operator works and give a real-life example where it might be useful.
Think about switching a light on/off using XOR.
You got /3 concepts.
Describe what happens to a binary number when you perform a left shift and a right shift.
Imagine moving digits in a number to the left or right.
You got /4 concepts.