Software Engineer (SDE)dsaintermediate3 interactive MCQs in app
Basic Bit Operations & Tricks
bitmasking with & and <<n & (n - 1) lowest set bit removalXOR self-cancellation properties
Core Concept
Bitwise operators manipulate individual binary bits directly in O(1) CPU instructions: AND (&) masks bits (1 only if both bits are 1), OR (|) sets bits, XOR (^) toggles/detects differences (a ^ a = 0, a ^ 0 = a), left shift (x << k) multiplies by 2^k, and right shift (x >> k) divides by 2^k.
Worked Example
to check if bit k=2 is set in n=6 (binary 0110), compute (6 & (1 << 2)) = 0110 & 0100 = 0100 != 0 (true). Clearing the lowest set bit uses n & (n - 1): for 6 (0110 & 0101 = 0100).
Common Pitfall
confusing bitwise & / | with logical && / ||, or overlooking operator precedence where == binds tighter than &.
Recommended Readings & Practice
Practice Basic Bit Operations & Tricks with 3 graded MCQs & written feedback.
Take SOARDO’s free 12-question diagnostic to see how strong you are across your target role and unlock adaptive daily missions.