Bits Light Up
XOR cancellation and bit-clearing made visible.
This animation renders numbers the way the machine sees them: rows of 32 bit cells, lit where the bit is 1.
In XOR mode, the rows of an array like [4, 1, 2, 1, 2] stack up, and the fold runs column by column. Watch what happens inside each column: paired 1s collide and cancel in a spark — that is x ^ x = 0 happening per bit — while a lone 1 passes through untouched. When the dust settles, only the bits of the single unpaired number remain lit, and they reassemble into the decimal answer. Notice that the order of the rows never matters: cancellation is about parity (odd or even counts of 1s per column), which is exactly why XOR-folding an array finds the element that appears an odd number of times.
In n & (n-1) mode, one number's bits are displayed while the expression fires repeatedly. Each application snaps off the lowest lit bit — one satisfying click per iteration — and the iteration counter at the end equals the number of set bits. Watch the subtraction's mechanism on the way: n-1 flips the lowest 1 and everything below it, and the AND wipes precisely that region clean.