◄ WORLD V · SONNY 5DART 039 · a helldive at the net

REFLECTED BINARY one bit at a time

Count in binary and, crossing 7→8, four bits flip at once (0111→1000). If those bits arrive at slightly different instants, a sensor reads garbage. The Gray code reorders the counts so that exactly one bit ever changes between neighbours — and the whole thing is a single line: n ⊕ (n >> 1), which I-13 now computes.

THE TECHNIQUE g(n) = n XOR (n >> 1)

To get the n-th Gray code, XOR n with itself shifted right by one. Consecutive rows below differ in exactly one bit (highlighted) — where plain binary sometimes flips several. live demo

gray(n) = n ^ (n >> 1) // one operator; I-13 runs it
nbinarygray = n^(n>>1)bits changed

HISTORY & CREDIT a name that stuck to the wrong century

“Gray code” sounds like Gray invented it; he gave it a patent and a name, not its origin. cited

1878 · Émile Baudot uses a reflected binary code in his telegraph — decades before “Gray”.
older still · the same single-change ordering appears in the Baguenaudier (Chinese rings) puzzle, centuries old.
1947–53 · Frank Gray at Bell Labs patents its use in a vacuum-tube PCM system to stop mis-reads; the patent fixes the name.
why it matters · rotary encoders, Karnaugh maps, genetic algorithms, and error-tolerant analog-to-digital all lean on the one-bit-change property.

Credit is a naming accident here: Gray’s patent made the label, Baudot made the code. misnamed

RECOMMEND FOR I-13 one operator, now native

The entire code is a single bitwise expression — ^ and >>, both integrated this campaign. It runs, exactly:

$ i13 run gray.i13 g4 = 6 g5 = 7 g6 = 5 g7 = 4 # 100,101,110,111 -> 110,111,101,100
Recommend: nothing new — a clean no-wall. Worth stating because it is the smallest possible proof that the bitwise integration was correct: the defining formula of an entire encoding is one line I-13 evaluates to the right answers. Decode (Gray→binary) is a short XOR-fold, also native.
The pattern: darts 038 and 039 both fell out of one integration (bitwise). One ask, integrated, keeps clearing walls — the campaign compounding.