/    /  Digital Logic-Gray Code

Gray Code

 

Gray code is an ordering of the binary number system such that two successive values differ in only 1-bit. They are useful in the normal sequence of the binary numbers generated by the hardware that can cause error, the gray code eliminates the problem as in this only 1-bit changes its value during transition from one number to another. 

 

Construction of an n-bit gray code

It can be generated recursively using reflex and prefix method. 

It can be explained as follows:

  1. Code is generated for n=1. code=0,1.
  2. Taking the previous code in sequence: 0,1.
  3. Then reverse the codes and add them to the sequenced code: 0,1,1,0.
  4. Then the prefix 0 is added to the previous codes and prefix 1 is added to the newer codes: 00,01,11,10.

 

For example, the gray code is as follows for the given n values:

 

For n=1-bit

Binary Gray
00
11

 

For n=2-bit

BinaryGray
0000
0101
1011
1110

 

For n=3-bit

BinaryGray
000000
001001
010011
011010
100110
101111
110101
111100

 

 

Reference

Gray Code