Gray Code

Last Updated : 25 Apr, 2026

Gray code is a binary numbering system in which two consecutive values differ by only one bit, so it is also called reflected binary code or unit distance code; this single-bit change helps reduce errors during transitions, especially in digital and hardware systems, where normal binary counting may change multiple bits at once and cause ambiguity; in Gray code, the sequence is formed in such a way that the first half of the values is reflected in reverse order to generate the second half.

Characteristics and Properties of Gray Code

  • Single Bit Change: Gray code only allows for one bit to change when changing from one value to another. Because there is less ambiguity when changing values, this feature lessens the possibility of errors and glitches in digital systems.
  • Reflection Property: A straightforward way for creating the Gray Code sequence entails reflecting the current sequence before prefixing the new sequence with a new bit. For instance, start with a 2-bit Gray Code sequence and reflect it to make a 3-bit Gray Code sequence. The single-bit change property is upheld by the reflection property, which also makes sure the sequence is cyclic.

Types of Gray Codes

  • Binary Reflected Gray Code: The most typical kind of Gray code utilized in digital systems is the binary reflected Gray code, also referred to as the reflected Gray code. Each succeeding number in this code differs from the one before it by a single bit. The binary code for each number is mirrored before being transformed into the Gray code, which is how the code gets its name.
  • Balanced Gray Code: Transition counts has equal in balanced Gray code. it is a unique variety of gray code in which every potential value appears exactly once in the sequence. A good example of where this kind of Gray coding is important in analog-to-digital converters. 
  • N-ary Gray Code: This Gray code consist non-Boolean values like sequences of 1, 2, 3. 
  • Two dimentional Gray code: This kind of Gray code is helpful in error correction.
  • Sequential Gray Code: Every number in the sequence is either the predecessor or the successor of the one before it. Certain applications, including robotics and manufacturing procedures, use this kind of Gray code.

Conversion of Gray Code

Gray code and binary conversion are essential for understanding and resolving issues in digital systems. The most significant bit (MSB) of a binary integer is converted to gray code by taking the XOR of the bit that is now in use and the bit that is immediate to its left in the binary representation.

what-is-gray-code-1_480
n Bit Gray Code

The below table represents the gray code of decimals from 0 to 10.

DecimalBinary CodeGray 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

8

1000

1100

9

1001

1101

10

1010

1111

To Generate Gray Code

Recursively, the prefix and reflect methods are used to create a number's Gray code. To create gray code:

  • We determine how many bits are necessary to represent a number.
  • The binary equivalent of 0 is found next, which is the code 0000.
  • The most important portion of the preceding code, 0000, will now be changed.
  • Until all of the codes cannot be uniquely identified, we carry out this process in reclusively.
  • If we change the most significant bit and still get the same code as before, we change the second-most significant bit, and so on.
what-is-gray-code-2
Generating Gray Code

Applications of Gray Code

Comment
Article Tags:

Explore