Library

FST · Rational transduction

Binary → Gray code

Streams a binary number into its Gray code (output = bit XOR previous bit). Adjacent values end up differing in exactly one bit — the trick rotary encoders rely on.

prev 0prev 10/01/11/00/1
The machine as drawn — 2 states, 4 transitions.

The author’s examples, run

1011 → reject · 11101111 → reject · 10000110 → reject · 01010111 → reject · 01001000 → reject · 1100