Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to double the value using bit manipulation.
DSA C#
int result = number [1] 1;
Attempts:
3 left
💡 Hint
Common Mistakes
Using right shift >> which halves the number.
Using addition + which works but is not bit manipulation.
✗ Incorrect
Left shifting by 1 bit multiplies the number by 2.
2fill in blank
mediumComplete the code to check if a number is even using bit manipulation.
DSA C#
bool isEven = (number [1] 1) == 0;
Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise OR | which does not check the last bit.
Using XOR ^ which toggles bits.
✗ Incorrect
Using bitwise AND with 1 checks the least significant bit; if 0, number is even.
3fill in blank
hardFix the error in the code to toggle the 3rd bit of a number.
DSA C#
int toggled = number [1] (1 << 2);
Attempts:
3 left
💡 Hint
Common Mistakes
Using AND & which clears bits.
Using OR | which sets bits but does not toggle.
✗ Incorrect
XOR ^ toggles the bit at the specified position.
4fill in blank
hardFill both blanks to create a mask that extracts the last 4 bits of a number.
DSA C#
int mask = (1 [1] 4) [2] 1;
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition instead of subtraction changes mask value.
Using OR | instead of subtraction results in wrong mask.
✗ Incorrect
Shift 1 left by 4 bits then subtract 1 to get mask 0b1111 (last 4 bits).
5fill in blank
hardFill all three blanks to set the 5th bit of a number and clear the 2nd bit.
DSA C#
number = (number [1] (1 << 4)) [2] ([3] (1 << 1));
Attempts:
3 left
💡 Hint
Common Mistakes
Using XOR ^ instead of OR | to set bits.
Not negating the mask when clearing bits.
✗ Incorrect
Use OR | to set 5th bit, AND & with NOT ~ mask to clear 2nd bit.
