Recall & Review
beginner
What does the bitwise AND operator (&) do in Rust?
It compares each bit of two numbers and returns a new number where each bit is 1 only if both bits in the original numbers were 1; otherwise, the bit is 0.
Click to reveal answer
beginner
Explain the bitwise OR operator (|) in Rust.
It compares each bit of two numbers and returns a new number where each bit is 1 if at least one of the bits in the original numbers was 1; otherwise, the bit is 0.
Click to reveal answer
beginner
What is the purpose of the bitwise XOR operator (^) in Rust?
It compares each bit of two numbers and returns a new number where each bit is 1 if the bits are different (one is 1 and the other is 0); if the bits are the same, the bit is 0.
Click to reveal answer
beginner
How does the bitwise NOT operator (~) work in Rust?
It flips every bit of a number: all 1 bits become 0, and all 0 bits become 1. Note: In Rust, the bitwise NOT operator is ~, not !.
Click to reveal answer
intermediate
What do the left shift (<<) and right shift (>>) operators do in Rust?
Left shift (<<) moves all bits in a number to the left by a specified number of places, adding zeros on the right. Right shift (>>) moves bits to the right, discarding bits on the right and filling in on the left depending on the type.
Click to reveal answer
What is the result of 5 & 3 in Rust? (5 = 0101, 3 = 0011 in binary)
✗ Incorrect
Bitwise AND compares bits: 0101 & 0011 = 0001, which is 1 in decimal.
Which operator flips all bits of a number in Rust?
✗ Incorrect
The ~ operator is the bitwise NOT operator that flips all bits.
What does the expression 4 << 1 evaluate to in Rust?
✗ Incorrect
Left shifting 4 (0100) by 1 bit gives 1000, which is 8.
Which bitwise operator returns 1 only if bits are different?
✗ Incorrect
The XOR (^) operator returns 1 when bits differ.
What is the result of 7 | 2 in Rust? (7 = 0111, 2 = 0010 in binary)
✗ Incorrect
Bitwise OR: 0111 | 0010 = 0111, which is 7.
Describe how the bitwise AND, OR, and XOR operators work with simple examples.
Think about comparing bits like switches being on or off.
You got /4 concepts.
Explain what happens when you use left shift (<<) and right shift (>>) operators on a number.
Imagine sliding beads on a string to the left or right.
You got /3 concepts.