Apex › Data & encoding
Why encoders use Gray code (one bit at a time)
A rotary or optical encoder reads its position as bits, and plain binary flips several bits at a carry boundary (3→4 is 011→100) — so a mistimed read mid-transition can be garbage like 7 or 0. Gray code reorders the values so consecutive ones differ by exactly one bit, so any read is off by at most one. Build it by reflect-and-prefix, or gray(n)=n XOR (n≫1). Verified: every consecutive pair (incl. wrap) differs by one bit. Step the dial and compare binary vs Gray. Used in encoders, clock-domain counters, and Karnaugh maps.
More in Data & encoding
- Encoding
- How a computer stores a fraction (IEEE-754)
- Varint & zigzag
- Base58 & Base58Check
- Line coding
- LZ77 compression
- LZW compression
- Burrows-Wheeler
- How genomes are assembled (de Bruijn graphs)
- Move-to-front
- Content-defined chunking
- rsync (delta sync)
- Finite automata (DFA)
- Huffman coding
- How JPEG compresses an image
- How content-aware resize works (seam carving)
- How video inter-frame compression works
- How MP3 shrinks audio (psychoacoustic masking)
- How dithering fakes gray with black & white
- Why 128 isn’t half-bright (gamma)
- Why RGB blends look muddy (OKLab)
- How HDR fits the sun on your screen (tone-mapping)
- Golomb-Rice coding
- Elias γ/δ coding
- Gorilla (time-series)
- COBS (byte stuffing)
- Arithmetic coding
- CRC-32 walk
- Hamming(7,4) code
- Reed-Solomon
- Viterbi / convolutional
- Error control
- How a barcode works (UPC check digit)
- How a QR code is built (Reed-Solomon + masking)