Why it matters
Bit tricks eliminate branches in hot loops. Understanding them shapes performance intuition.
Advertisement
The architecture
x & (x-1) clears lowest set bit; x & -x isolates it.
XOR swap avoids temp variable.
Parity by fold-XOR.
Advertisement
How it works end to end
Kernighan's popcount loop.
Parity via fold and XOR reduction.
Swap without temp using XOR.