Conversion from Gray Code to Binary Code and Vice Versa
Conversion from Gray Code to Binary Code
Let Gray Code be g3 g2 g1 g0. Then the respective Binary Code can be obtained as follows:
i.e.
b3 = g3
b2 = b3 ⊕ g2
b1 = b2 ⊕ g1
b0 = b1 ⊕ g0
Example:
Gray Code: g3 g2 g1 g0 = 1 0 0 1 then Binary Code: b3 b2 b1 b0
b3 = g3 = 1
b2 = b3 ⊕ g2 = 1 ⊕ 0 = 1
b1 = b2 ⊕ g1 = 1 ⊕ 0 = 1
b0 = b1 ⊕ g0 =1 ⊕ 1 = 0
∴ Final Binary Code: 1 1 1 0
Conversion from Binary code to Gray Code
Let Binary code be b3 b2 b1 b0. Then the respective Gray Code can be obtained is as follows
i.e.
g3 = b3
g2 = b3 ⊕ b2
g1 = b2 ⊕ b1
g0 = b1 ⊕ b0
Example:
Binary Code: b3 b2 b1 b0 = 1 1 1 0 Gray Code: g3 g2 g1 g0
g3 = b3 = 1
g2 = b3 ⊕ b2 = 1 ⊕ 1 = 0
g1 = b2 ⊕ b1 = 1 ⊕ 1 = 0
g0 = b1 ⊕ b0 =1 ⊕ 0 = 1
∴ Final Gray code: 1 0 0 1
Conversion Table from Binary to Gray Code:
Decimal | Binary | Gray |
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 |
11 | 1011 | 1110 |
12 | 1100 | 1010 |
13 | 1101 | 1011 |
14 | 1110 | 1001 |
15 | 1111 | 1000 |
Source:TESTBOOK