Gray code

You will learn

Why Gray code changes one bit at a time, and what a test suite that never reads pointers cannot see.

Gray code changes exactly one bit per step, so a sample taken mid-change reads one of two adjacent codes -- off by one, never garbage. A FIFO whose read and write pointers count in Gray can be sampled across domains safely, and the flags derived from them hold. The recording plants a mutation that Gray would have caught red-handed if the tests had looked: (state.head_ptr + 1) becomes + 3, and every test still passes, because the suite asserts fill and flags, never pointer values. A test suite defends what it reads; the encoding is defended by the next lesson's rule, not by these tests. The recording restores the spec and prints its sha256.

Open the interactive lesson →