Challenge - 5 Problems
Bit Manipulation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this bitwise AND operation?
Consider the following Python code snippet:
What will be printed?
result = 12 & 5 print(result)
What will be printed?
DSA Python
result = 12 & 5 print(result)
Attempts:
2 left
💡 Hint
Think about the binary form of 12 and 5 and where both have 1s.
✗ Incorrect
12 in binary is 1100, 5 is 0101. Bitwise AND keeps bits set only where both are 1.
1100 & 0101 = 0100 which is 4 in decimal.
❓ Predict Output
intermediate2:00remaining
What is the output after left shifting?
What does this code print?
num = 3 result = num << 2 print(result)
DSA Python
num = 3 result = num << 2 print(result)
Attempts:
2 left
💡 Hint
Left shift by 2 means multiply by 2 twice.
✗ Incorrect
3 in binary is 11. Left shifting by 2 adds two zeros: 1100 which is 12 decimal.
❓ Predict Output
advanced2:00remaining
What is the output of this XOR and NOT combination?
Analyze this code:
What is printed?
a = 10 b = 7 result = ~(a ^ b) print(result)
What is printed?
DSA Python
a = 10 b = 7 result = ~(a ^ b) print(result)
Attempts:
2 left
💡 Hint
First find XOR, then apply NOT (bitwise complement).
✗ Incorrect
10 in binary is 1010, 7 is 0111. XOR: 1010 ^ 0111 = 1101 (13 decimal).
In Python, ~x = -x - 1, so ~13 = -14.
❓ Predict Output
advanced2:00remaining
What is the output after right shifting a negative number?
Consider this code:
What is printed?
num = -16 result = num >> 2 print(result)
What is printed?
DSA Python
num = -16 result = num >> 2 print(result)
Attempts:
2 left
💡 Hint
Right shift divides by 2, rounding down for negatives.
✗ Incorrect
-16 in binary is represented in two's complement.
Right shifting by 2 divides by 4, rounding towards negative infinity.
-16 >> 2 = -4.
🧠 Conceptual
expert3:00remaining
How many bits are set to 1 after this operation?
Given the code:
What number is printed?
num = 29
result = num & (num >> 1)
count = bin(result).count('1')
print(count)What number is printed?
DSA Python
num = 29 result = num & (num >> 1) count = bin(result).count('1') print(count)
Attempts:
2 left
💡 Hint
Check binary of 29 and 29 shifted right by 1, then AND them.
✗ Incorrect
29 in binary: 11101
29 >> 1: 01110 (14 decimal)
11101 & 01110 = 01100 (12 decimal)
Number of 1s in 01100 is 2.