Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to double the number using bit manipulation.
DSA Python
result = num [1] 1
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using right shift (>>) instead of left shift (<<).
Using arithmetic operators instead of bit shifts.
✗ Incorrect
Shifting bits to the left by 1 (<< 1) multiplies the number by 2 efficiently.
2fill in blank
mediumComplete the code to check if a number is even using bit manipulation.
DSA Python
is_even = (num [1] 1) == 0
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise OR (|) instead of AND (&).
Using shift operators instead of bitwise AND.
✗ 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 Python
result = num [1] (1 << 2)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using AND (&) which clears bits instead of toggling.
Using OR (|) which sets bits but does not toggle.
✗ Incorrect
XOR (^) toggles the bit at the specified position without affecting others.
4fill in blank
hardFill both blanks to create a mask that clears the 4th bit of a number.
DSA Python
mask = ~(1 [1] 3) result = num [2] mask
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR (|) instead of AND (&) to clear bits.
Not inverting the mask before AND operation.
✗ Incorrect
Shift 1 left by 3 to target 4th bit, then invert mask and AND with number to clear that bit.
5fill in blank
hardFill all three blanks to extract bits 2 to 4 (inclusive) from a number.
DSA Python
mask = ((1 [1] 3) - 1) [2] (1 [3] 1) result = (num & mask) >> 1
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using AND (&) instead of OR (|) to combine mask parts.
Incorrect shift amounts causing wrong bits to be selected.
✗ Incorrect
Shift 1 left by 3, subtract 1 to set bits 0-2, left shift by (1 | 1)=1 to position mask at bits 1-3 (0-based, i.e., 2nd-4th bits 1-based), AND extracts them, >>1 aligns to lowest bits.