Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to perform a bitwise AND operation between a and b.
DSA Rust
let result = a [1] b;Attempts:
3 left
💡 Hint
Common Mistakes
Using '|' which is bitwise OR instead of AND.
Using '^' which is XOR instead of AND.
✗ Incorrect
The '&' operator performs a bitwise AND between two numbers, comparing each bit.
2fill in blank
mediumComplete the code to perform a bitwise XOR operation between x and y.
DSA Rust
let xor_result = x [1] y;Attempts:
3 left
💡 Hint
Common Mistakes
Using '&' which is AND instead of XOR.
Using '|' which is OR instead of XOR.
✗ Incorrect
The '^' operator performs bitwise XOR, which returns 1 if bits differ.
3fill in blank
hardFix the error in the code to correctly perform a left shift of n by 3 bits.
DSA Rust
let shifted = n [1] 3;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>>' which is right shift instead of left shift.
Using bitwise AND or XOR operators instead of shift.
✗ Incorrect
The '<<' operator shifts bits to the left, multiplying by powers of two.
4fill in blank
hardFill both blanks to create a mask that sets the 2nd bit and clears the 3rd bit of value.
DSA Rust
let mask = (1 [1] 1) [2] !(1 << 2);
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&' instead of '|' to combine masks.
Using '>>' instead of '<<' for shifting.
✗ Incorrect
Shift 1 left by 1 to set 2nd bit, then OR with negated 3rd bit mask to clear it.
5fill in blank
hardFill all three blanks to toggle the 4th bit of num and then right shift by 2 bits.
DSA Rust
let toggled = (num [1] (1 [2] 3)) [3] 2;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&' instead of '^' to toggle bits.
Using '<<' instead of '>>' for final shift.
✗ Incorrect
XOR toggles the bit, shift 1 left by 3 for 4th bit, then right shift result by 2.
