Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to perform bitwise AND of two numbers.
DSA C++
int result = a [1] b;Attempts:
3 left
💡 Hint
Common Mistakes
Using '|' instead of '&' for AND operation.
Using '^' which is XOR, not AND.
✗ Incorrect
The bitwise AND operator '&' compares each bit of two numbers and returns 1 only if both bits are 1.
2fill in blank
mediumComplete the code to perform bitwise OR of two numbers.
DSA C++
int result = x [1] y;Attempts:
3 left
💡 Hint
Common Mistakes
Using '&' instead of '|' for OR operation.
Confusing OR with XOR '^'.
✗ Incorrect
The bitwise OR operator '|' compares each bit of two numbers and returns 1 if at least one bit is 1.
3fill in blank
hardFix the error in the code to correctly perform bitwise NOT on a number.
DSA C++
int result = [1]num;Attempts:
3 left
💡 Hint
Common Mistakes
Using '^' which is XOR, not NOT.
Using '&' or '|' which are AND/OR operators.
✗ Incorrect
The bitwise NOT operator '~' flips all bits of the number.
4fill in blank
hardFill both blanks to shift bits left by 2 positions and then right by 1 position.
DSA C++
int shifted = (value [1] 2) [2] 1;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' or '-' instead of shift operators.
Reversing the order of shifts.
✗ Incorrect
Left shift '<<' moves bits to the left, multiplying by 2 for each shift. Right shift '>>' moves bits to the right, dividing by 2 for each shift.
5fill in blank
hardFill all three blanks to create a mask that sets the 3rd bit (from right, zero-based) of number n.
DSA C++
int mask = 1 [1] 3; int result = n [2] mask; int cleared = n [3] mask;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '^' instead of '&~' to clear bit.
Not shifting 1 to correct bit position.
✗ Incorrect
Shift 1 left by 3 to create mask. Use OR '|' to set the bit. Use AND with NOT '&~' to clear the bit.
