Section Recap

Summary of bit manipulation.

You've learned bitwise operations and common patterns.

Operators: AND, OR, XOR, NOT, shifts.

Common tricks:

  • Check/set/clear/toggle bit ii.
  • Count set bits (popcount).
  • Clear or isolate lowest set bit.
  • Check power of two.

XOR magic: Self-inverse property finds unique elements.

Bitmask DP: Represent sets as integers for compact state.

When to use:

  • Subset enumeration.
  • Compact state representation.
  • Finding duplicates or missing elements.
  • Low-level optimization.

Bit manipulation is a powerful tool. Learn it and you'll find clever solutions to problems that seem to require complex data structures.