Bit Manipulation and Number Theory

Low-level operations used in optimization, hashing, subset processing, number theory, and algorithmic math tricks.

1.0 Bitwise Fundamentals

  1. Set/unset/check/toggle bits
  2. Shift operations
  3. Bit count and masks

2.0 XOR Patterns

  1. Single number (odd frequency)
  2. Pairwise XOR logic
  3. Missing number, duplicate detection

3.0 Bitmasking

  1. Subset generation
  2. Set cover and DP
  3. Bitwise DP state compression

4.0 Advanced Bit Tricks

  1. Brian Kernighan’s algorithm
  2. Lowest set bit
  3. Divide/multiply using shifts

5.0 Number Properties

  1. Prime number sieve
  2. Perfect squares and roots
  3. Palindromes, Armstrong, etc.

6.0 Modular Arithmetic

  1. Mod inverse
  2. Modulo multiplication/division
  3. Overflow prevention

7.0 GCD / LCM and Euclid’s Algorithm

  1. Standard GCD
  2. Extended Euclidean Algorithm
  3. LCM derivation

8.0 Combinatorics

  1. Factorials, nCr
  2. Pascal’s Triangle
  3. DP + combinatorics (unique paths, Catalan)

9.0 Base Conversions and Encodings

  1. Decimal ↔ Binary/Hex/Base62
  2. Excel column name ↔ Number
  3. Custom radix encoding/decoding