Skip to content

Latest commit

 

History

History

README.md

Bit Manipulation

Bitwise operations and bit tricks for efficient problem solving.

Key Concepts Covered

  • Bitwise operators (&, |, ^, ~, <<, >>)
  • Set, clear, toggle, and check bits
  • Count set bits (Kernighan's algorithm)
  • XOR properties and applications
  • Bit masking
  • Power of 2 checks
  • Binary string operations

Problems in this Directory

Counting Bits

Single Number Problems

Binary String Operations

Bitwise Operations

Tips

  • XOR is super useful: a^a=0, a^0=a
  • Use & 1 to check if number is odd
  • Use << and >> for fast multiplication/division by 2
  • ~n equals -(n+1) in two's complement
  • Practice bit manipulation—it's often the key to O(1) solutions