Algorithms / 3 visualizations
Bit Manipulation Visualizers
AND, XOR and shifts: tricks that turn loops into one-liners.
Open the lab → Every one runs on your own input, step by step, with the code highlighted in Java, Python, C++, C or JavaScript. Free, no sign-up.
All bit manipulation visualizations
- Count Set Bits (Kernighan)O(k)
Subtracting 1 flips the lowest 1 bit to 0 and every 0 below it to 1. So n & (n − 1) erases exactly the lowest 1 bit. Count how many times you can do that before n is 0.
- Single Number with XORO(n)
XOR is 1 where two bits differ. x ^ x = 0 and x ^ 0 = x, and the order does not matter. So XOR everything: each pair cancels itself, and only the single value is left.
- Subsets with a BitmaskO(n·2ⁿ)
Count mask from 0 to 2ⁿ − 1. Bit i of the mask says whether value i is in the subset. Counting in binary therefore lists every subset exactly once.