24
Digital Electronics
Table 2.4 Generation of higher-bit Gray code numbers.
One-bit Gray code
Two-bit Gray code
Three-bit Gray code
Four-bit Gray code
0
0
00
00
000
000
0000
1
1
01
01
001
001
0001
1
11
11
011
011
0011
0
10
10
010
010
0010
10
110
110
0110
11
111
111
0111
01
101
101
0101
00
100
100
0100
100
1100
101
1101
111
1111
110
1110
010
1010
011
1011
001
1001
000
1000
2.3.1 Binary–Gray Code Conversion
A given binary number can be converted into its Gray code equivalent by going through the following
steps:
1. Begin with the most significant bit (MSB) of the binary number. The MSB of the Gray code
equivalent is the same as the MSB of the given binary number.
2. The second most significant bit, adjacent to the MSB, in the Gray code number is obtained by
adding the MSB and the second MSB of the binary number and ignoring the carry, if any. That is,
if the MSB and the bit adjacent to it are both ‘1’, then the corresponding Gray code bit would be a
‘0’.
3. The third most significant bit, adjacent to the second MSB, in the Gray code number is obtained
by adding the second MSB and the third MSB in the binary number and ignoring the carry, if any.
4. The process continues until we obtain the LSB of the Gray code number by the addition of the LSB
and the next higher adjacent bit of the binary number.
The conversion process is further illustrated with the help of an example showing step-by-step
conversion of (1011) 2 into its Gray code equivalent:
Binary
1011
Gray code 1- - -
Binary
1011
Gray code 11- -
Binary
1011
Gray code 111Binary
1011
Gray code 1110
Digital Electronics
Table 2.4 Generation of higher-bit Gray code numbers.
One-bit Gray code
Two-bit Gray code
Three-bit Gray code
Four-bit Gray code
0
0
00
00
000
000
0000
1
1
01
01
001
001
0001
1
11
11
011
011
0011
0
10
10
010
010
0010
10
110
110
0110
11
111
111
0111
01
101
101
0101
00
100
100
0100
100
1100
101
1101
111
1111
110
1110
010
1010
011
1011
001
1001
000
1000
2.3.1 Binary–Gray Code Conversion
A given binary number can be converted into its Gray code equivalent by going through the following
steps:
1. Begin with the most significant bit (MSB) of the binary number. The MSB of the Gray code
equivalent is the same as the MSB of the given binary number.
2. The second most significant bit, adjacent to the MSB, in the Gray code number is obtained by
adding the MSB and the second MSB of the binary number and ignoring the carry, if any. That is,
if the MSB and the bit adjacent to it are both ‘1’, then the corresponding Gray code bit would be a
‘0’.
3. The third most significant bit, adjacent to the second MSB, in the Gray code number is obtained
by adding the second MSB and the third MSB in the binary number and ignoring the carry, if any.
4. The process continues until we obtain the LSB of the Gray code number by the addition of the LSB
and the next higher adjacent bit of the binary number.
The conversion process is further illustrated with the help of an example showing step-by-step
conversion of (1011) 2 into its Gray code equivalent:
Binary
1011
Gray code 1- - -
Binary
1011
Gray code 11- -
Binary
1011
Gray code 111Binary
1011
Gray code 1110
