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
beginner
What does the NOT (~) operator do to a bit?
The NOT operator flips the bit: 1 becomes 0, and 0 becomes 1.<br>Example: ~1 = 0, ~0 = 1 (in binary representation).
Click to reveal answer
beginner
What happens when you perform a left shift (<<) on a number?
Left shift moves all bits to the left by the given number of positions, adding zeros on the right.<br>This is like multiplying the number by 2 for each shift.<br>Example: 3 (011) << 1 = 6 (110).
Click to reveal answer
What is the result of 5 & 3 in binary? (5 = 0101, 3 = 0011)
✗ Incorrect
5 & 3 = 0101 & 0011 = 0001.
Which operator flips all bits of a number?
✗ Incorrect
NOT (~) flips all bits: 1 becomes 0 and 0 becomes 1.
What does the expression (6 >> 1) evaluate to? (6 = 0110 in binary)
✗ Incorrect
Right shift by 1 moves bits right, dropping the last bit: 0110 >> 1 = 0011 (3).
What is the result of 4 ^ 4?
✗ Incorrect
XOR of a number with itself is always 0.
Which bitwise operator returns 1 if either bit is 1?
✗ Incorrect
OR (|) returns 1 if at least one bit is 1.
Describe how the AND, OR, XOR, and NOT bitwise operators work with simple examples.
Think about how each operator treats pairs of bits.
You got /4 concepts.
Explain what happens when you perform left shift (<<) and right shift (>>) on a binary number.
Imagine sliding bits left or right in a row.
You got /4 concepts.
