0
0
DSA Pythonprogramming~20 mins

Bit Manipulation Basics AND OR XOR NOT Left Right Shift in DSA Python - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Bit Manipulation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this bitwise AND operation?
Consider the following Python code snippet:

result = 12 & 5
print(result)

What will be printed?
DSA Python
result = 12 & 5
print(result)
A4
B1
C0
D8
Attempts:
2 left
💡 Hint
Think about the binary form of 12 and 5 and where both have 1s.
Predict Output
intermediate
2: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)
A9
B6
C8
D12
Attempts:
2 left
💡 Hint
Left shift by 2 means multiply by 2 twice.
Predict Output
advanced
2:00remaining
What is the output of this XOR and NOT combination?
Analyze this code:

a = 10
b = 7
result = ~(a ^ b)
print(result)

What is printed?
DSA Python
a = 10
b = 7
result = ~(a ^ b)
print(result)
A4
B6
C-14
D-4
Attempts:
2 left
💡 Hint
First find XOR, then apply NOT (bitwise complement).
Predict Output
advanced
2:00remaining
What is the output after right shifting a negative number?
Consider this code:

num = -16
result = num >> 2
print(result)

What is printed?
DSA Python
num = -16
result = num >> 2
print(result)
A-4
B-8
C4
D8
Attempts:
2 left
💡 Hint
Right shift divides by 2, rounding down for negatives.
🧠 Conceptual
expert
3:00remaining
How many bits are set to 1 after this operation?
Given the code:

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)
A3
B2
C4
D1
Attempts:
2 left
💡 Hint
Check binary of 29 and 29 shifted right by 1, then AND them.