Free engineering calculators and unit convertersceo@instrumentationblog.in
Signals and PLC · Glossary

What is Gray Code?

one bit change codeSignals and PLC

Gray code is a binary code in which only one bit changes between consecutive values, avoiding false readings in position encoders.

Advertisement

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

G = B XOR (B ≫ 1)
Bbinary value
≫ 1shift right by one bit
Example: Binary 0111 (7) becomes Gray 0100; binary 1000 (8) becomes Gray 1100.
Advertisement

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.

You May Also Like

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 Article

Related Terms

More Signals and PLC Terms

All signals and plc terms · Full glossary A to Z

Advertisement