Graycodes
Gray codes are a binary numeral system in which two successive values differ in only one bit. This single-bit change property minimizes errors during transitions in digital systems. The most common form is the binary-reflected Gray code (BRGC), which can be generated by the rule g = b XOR (b >> 1), where b is the binary representation and g is the Gray code. BRGC sequences are of length 2^n for n bits and form a cyclic sequence, so the first and last codewords differ by a single bit.
For example, the three-bit BRGC is: 000, 001, 011, 010, 110, 111, 101, 100. Gray codes traverse
Conversions between binary and Gray code are standard: binary to Gray uses g = b XOR (b >>
Applications include rotary encoders, where Gray coding prevents misreadings during motion, and certain digital-to-analog or analog-to-digital