Work out gray code instantly with clear inputs, formula shown and shareable results.
Gray code is formed by XORing a value with itself shifted right one place. Consecutive Gray codes differ in exactly one bit, which prevents transient misreads in rotary encoders and mechanical counters.
Binary to Gray
g = v XOR (v >> 1)
1001 XOR 0100 = 1101.
If several bits changed at once, a sensor reading mid-transition could return a wildly wrong value; with Gray code the worst error is one step.