juniorBit Manipulation
How to clear the i-th bit of a number?
Updated Apr 28, 2026
Short answer
Use the AND operator with a negated bitmask: num & ~(1 << i).
Deep explanation
Bit manipulation at the hardware level is faster than arithmetic. Use the AND operator with a negated bitmask: num & ~(1 << i). This is fundamental for low-level optimization.
Real-world example
Flag management in simple game engines.
Common mistakes
- Forgetting that bitwise operators have lower precedence than comparison operators.
Follow-up questions
- What is 1 << 3?