Gray code is a digital code, which is neither arithmetic nor weighted. There are no weights assigned to the bit positions of a Gray code. Moreover, we do not use Gray code for arithmetic operations. The advantage of Gray code is that it is very less error susceptible while encoding data compared to the straight binary code. This is because the Gray code exhibits a single-bit change from one code word to the next in sequence. The following table lists the binary as well as Gray codes for decimal numbers 0 to 7.
Decimal Number | Binary Code | Gray Code |
0 | 000 | 000 |
1 | 001 | 001 |
2 | 010 | 011 |
3 | 011 | 010 |
4 | 100 | 110 |
5 | 101 | 111 |
6 | 110 | 101 |
7 | 111 | 100 |
Let’s verify the special property of the Gray code, which is a single-bit change in adjacent code words.
For example, in the case of decimal numbers 3 and 4, the binary codes are 011 and 100, whereas Gray codes are 010 and 110. We can observe that in the case of binary code, from 3 to 4 there are changes in all three bits. However, in the case of Gray code, only the MSB bit got changed (single bit change). This property of Gray code is beneficial for multiple electromechanical applications of digital systems for efficient error detection and correction. We should notice over here that even the last and the first entry also differ by only 1 bit. This is known as the cyclic property of the gray code.
The following series of articles will cover different concepts of Gray code.