encode | decode | visualize

> gray | reflected | binary <

// Gray Code - Binary numeral system with single-bit transitions

0 chars
0 chars

>> features

[SINGLE-BIT]

Unit Distance

Only one bit changes between consecutive values.

[ERROR-REDUCTION]

Error Minimization

Reduces errors in analog-to-digital conversion.

[CYCLIC]

Cyclic Property

First and last values differ by only one bit.

>> technical info

How Gray Code Works

Gray code (reflected binary code) is a binary numeral system where two successive values differ in only one bit. Created by Frank Gray, it's formed by XORing each bit with the previous bit. This property makes it ideal for position encoders and error reduction in digital systems.

Gray Code Examples

Decimal | Binary | Gray Code
0       | 0000   | 0000
1       | 0001   | 0001
2       | 0010   | 0011
3       | 0011   | 0010
4       | 0100   | 0110
5       | 0101   | 0111
6       | 0110   | 0101
7       | 0111   | 0100

Note: Only 1 bit changes between consecutive Gray codes

Why Use Gray Code

  • Rotary encoders
  • Karnaugh maps
  • Error correction
  • Digital communications
  • Position sensors

>> frequently asked questions

What is Gray code?

Gray code, also known as reflected binary code, is a binary numeral system where two successive values differ in only one bit. It was invented by Frank Gray and is widely used in digital systems to prevent spurious output during transitions.

How to convert binary to Gray code?

To convert binary to Gray: 1) Keep the MSB (most significant bit) as is, 2) XOR each bit with the previous bit. Formula: G[i] = B[i] XOR B[i-1]. For example, binary 1011 becomes Gray 1110.

Why is Gray code better for encoders?

Gray code prevents ambiguous readings during transitions. In binary, changing from 7 (0111) to 8 (1000) requires changing all 4 bits simultaneously. If not perfectly synchronized, intermediate values could be read. Gray code ensures only one bit changes at a time.

Where is Gray code used?

Gray code is used in rotary encoders, Karnaugh map simplification, error correction in digital communications, genetic algorithms, and analog-to-digital converters. It's essential wherever single-bit transitions are needed.