You are on page 1of 6

How to construct Gray code?

 A 1-bit gray code has two code words 0 and 1


representing decimal numbers 0 and 1 resp.
 An n-bit (n≥2) Gray code will have first 2(n-1) Gray code
of (n-1) bits written in order with a leading 0 appended.
 The last 2(n-1) Gray codes will be equal to the Gray code
words of (n-1) bit Gray code written in reverse
order( assuming a mirror placed between first 2(n-1) and
last 2(n-1) Gray codes) with a leading 1 appended.
Construction Gray code

Decimal 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
0 0 0 0
n =1
0 0 0 1 n =2
0 0 1 1
0 0 1 0 n=3
0 1 1 0
0 1 1 1
0 1 0 1
0 1 0 0
n=4
1 1 0 0
1 1 0 1
1 1 1 1
1 1 1 0
Direct Conversion From Binary to Gray

 Start with the most significant bit of the binary


number.
 Copy this bit as the MSB of the gray code number.
 Xor the MSB of the binary to the next adjacent bit
of the binary number.
 Continue Xor ,each bit of the binary to the next bit
to its right to get the gray code for that position as
shown in the next slide
Conversion From Binary to Gray
Cont…
Direct Conversion From Gray to Binary

Example:

Gray  1 1 0 0 1

Binary  1 0 0 0 1

You might also like