Rotary encoder: why Gray, not binary — Gray code

exam standardthe failure Gray code prevents

Answer

4

Why this example is worth doing

The engineering reason the code exists. On a binary-coded shaft encoder, the step from 7 to 8 changes every bit at once, and if the sensors do not switch at precisely the same instant the reading passes through a spurious intermediate value — possibly 15, at the opposite end of the range. With Gray code only one track changes, so the worst case is reading the old value or the new one. The page cites Gray's 1953 patent.

Try your own input in the Gray code. Convert binary to reflected Gray code and back, and build the sequence by reflection.

How the answer is reached

Differing positions

a0111

b1000

4 of 4 positions differ, so the Hamming distance is 4.

Compare with

Open the Gray code

This input is entered in the tool itself — it is too rich for a link to carry.

Note:

Notation this page assumes

  • Bit strings are written most significant bit first, and bit 0 is the least significant bit.
  • A width is stated explicitly wherever it changes the answer; nothing is silently sign-extended or truncated.
  • Gray code here is the reflected binary code, generated by reflection, with the least significant bit changing first.

Sources

  • Gray, “Pulse Code Communication”, US Patent 2,632,058 (1953)