What is Gray Code?
Gray code is a binary code in which only one bit changes between consecutive values, avoiding false readings in position encoders.
Gray Code Explained
In plain binary, going from 7 (0111) to 8 (1000) changes four bits at once; if read mid change, any value can appear. Gray code changes one bit, so a misread is off by one step at most.
Absolute encoders use it; the PLC converts it to binary.
Gray Code Formula
| B | binary value |
| ≫ 1 | shift right by one bit |
Calculators for Gray Code
Frequently Asked Questions
What is Gray Code?
Gray code is a binary code in which only one bit changes between consecutive values, avoiding false readings in position encoders.
Why not use binary encoders?
Several bits changing together are never perfectly simultaneous, causing glitches.
How is Gray converted back?
Each binary bit is the XOR of all Gray bits from the top down to that bit.
Learn more on the blog
Introduction to number systems
A practical guide on instrumentationblog.in with more detail on gray code and how it is applied on real plants.
Read Full ArticleRelated Terms
More Signals and PLC Terms
All signals and plc terms · Full glossary A to Z