Published by: Nuru
Published date: 22 Jun 2021
Gray Code was named after Frank Gray. It is an ordering of binary number systems such that two successive values differ in only one bit. They are very useful in the normal sequence of binary numbers generated by the hardware that may cause an error or ambiguity during the transition from one number to the next. So, it can eliminate this problem easily since only one bit changes its value during any transition between two numbers. It is also used as a solution guide for the tower of Hanoi problem, used in labeling the axes of K-maps, and allows the system designers to perform error checking such as digital terrestrial television and some cable TV system.
Gray Code is also known as reflected code. It is used in applications where the normal sequence of binary numbers may produce an error or ambiguity during the transition from one number to the next.
It is not weighted which means it does not depend on the positional value of the digit. This cyclic variable code means every transition from one value to the next value involves only one-bit change.
n-bit Gray code can be generated recursively using the reflect and prefix method which is explained as following below.
Therefore, 0 and 1 are for Binary numbers 0 and 1 respectively. Gray codes: 00. 01, 11, and 10 are for Binary numbers: 00, 01, 10, and 11 respectively. Similarly, you can construct Gray code for 3-bit binary numbers:
Input | Output | ||||||
---|---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 |
0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 |
0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 |
0 | 1 | 0 | 0 | 0 | 1 | 1 | 0 |
0 | 1 | 0 | 1 | 0 | 1 | 1 | 1 |
0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 |
0 | 1 | 1 | 1 | 0 | 1 | 0 | 0 |
1 | 0 | 0 | 0 | 1 | 1 | 0 | 0 |
1 | 0 | 0 | 1 | 1 | 1 | 0 | 1 |