Bitwise Operators
Last Updated: 16th August 2025
Bitwise operators work at the binary level (0s and 1s).
They directly operate on the bits of integers.
Hinglish Tip 🗣: Ye operators number ke bits par kaam karte hain (0-1 ke form me).
✏ Syntax & Examples
a = 6 # binary: 110
b = 3 # binary: 011
print(a & b) # 2 -> 010
print(a | b) # 7 -> 111
print(a ^ b) # 5 -> 101
print(~a) # -7 -> two's complement
print(a << 1) # 12 -> 1100
print(a >> 1) # 3 -> 11
💡 Quick Practice
- Calculate 12 & 5 (hint: 12 = 1100, 5 = 0101).
- Try 7 | 4 and predict output.
- Check 9 ^ 5 → kya hoga?
- What will ~10 return?
- Use << to multiply 3 by 8 using shifting.
- Use >> to divide 40 by 4 using shifting.
- Exercises
