Gosper's Hack & Gray Code — Bit-Iteration Techniques

Mode 1: Gosper steps through k-subset bitmasks via c=x&-x, r=x+c, repack. Mode 2: Gray code flips exactly one bit between consecutive values.

step 0

Current bitmask

Sequence

Press Step to begin. Switch modes with the Gosper / Gray code buttons; adjust n and k.
Self-contained visualization. Gosper enumerates fixed-size subsets in increasing numeric order; Gray code lists all subsets so each step toggles one element. See junior.md and professional.md for the proofs that Gosper yields the smallest larger same-popcount integer and that each Gray step flips exactly one bit.