Challenge - 5 Problems
Bit Manipulation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Bitwise AND vs Arithmetic Multiplication
What is the output of the following Python code snippet?
DSA Python
a = 6 # binary 110 b = 3 # binary 011 result = a & b print(result)
Attempts:
2 left
💡 Hint
Remember that & is a bitwise AND operation, not multiplication.
✗ Incorrect
The bitwise AND of 6 (110) and 3 (011) is 2 (010 in binary).
Arithmetic multiplication would be 18, but here & is used.
❓ Predict Output
intermediate2:00remaining
Output of Left Shift vs Multiplication
What is the output of this code that uses left shift to multiply by 4?
DSA Python
x = 7 result = x << 2 print(result)
Attempts:
2 left
💡 Hint
Left shift by 2 bits multiplies the number by 2^2 = 4.
✗ Incorrect
Left shifting 7 by 2 bits is the same as multiplying 7 by 4.
7 * 4 = 28.
🔧 Debug
advanced2:00remaining
Why Does This Bitwise XOR Code Fail?
The code below is intended to toggle the 3rd bit of a number. What error or wrong output does it produce?
DSA Python
num = 10 # binary 1010 mask = 1 << 3 num = num ^ mask print(num)
Attempts:
2 left
💡 Hint
Remember bit positions start at 0 from the right.
✗ Incorrect
1 << 3 sets the 4th bit (counting from 0).
Toggling the 4th bit of 10 (1010) results in 2 (0010).
The 3rd bit is at position 2, so mask should be 1 << 2.
🧠 Conceptual
advanced2:00remaining
When Does Bit Manipulation Beat Arithmetic?
Which of the following is NOT a typical advantage of using bit manipulation over arithmetic operations?
Attempts:
2 left
💡 Hint
Think about what bit manipulation changes and what it does not.
✗ Incorrect
Bit manipulation does not reduce memory usage for large numbers.
It mainly improves speed and control over bits.
🚀 Application
expert3:00remaining
Output of Complex Bitwise Expression
What is the output of this Python code that combines multiple bitwise operations?
DSA Python
a = 12 # binary 1100 b = 5 # binary 0101 result = (a & b) | (a ^ b) print(result)
Attempts:
2 left
💡 Hint
Recall that (a & b) | (a ^ b) equals a | b.
✗ Incorrect
(a & b) | (a ^ b) simplifies to a | b.
12 (1100) | 5 (0101) = 13 (1101).