Gray Code: The reflected binary code or gray code is an ordering of binary number systems where two successive values differ in only one bit.
Properties of Gray Code:
i) Gray code is non-weighted BCD code.
ii) It is a cyclic code, i.e. unit distance code (successive code words differ in one-bit position only).
iii) It is reflective code (Gray codes for all decimal numbers can be generated through the reflective property).
# Distance means if two codes have changed only 1 bit, then the distance between two codes is 1.
So, the beauty of gray code is if we choose any two successive numbers, the distance between two numbers is always 1 (unit) that’s why gray code also called unit distance code.
Binary to Gray code conversion:
Say, an 8-bit binary number is
The equivalent Gray code will be
Where,
Gray code to Binary conversion:
Say, an 8-bit Gray Code is
The equivalent binary will be
Where,
Reflective Code:
Gray code also called reflective code because 'n' least significant bits for through are the mirror images of those for 0 through .
Example: We take examples to understand how gray code is reflective.
Decimal |
4-bit Binary | Gray Code | |||
1bit | 2 bit | 3 bit | 4 bit | ||
0 | 0000 | 0 | 00 | 000 | 0000 |
1 | 0001 | 1 | 01 | 001 | 0001 |
2 | 0010 |
| 11 | 0 1 1 | 0011 |
3 | 0011 | 10 | 0 1 0 | 0010 | |
4 | 0100 |
| 1 1 0 | 0110 | |
5 | 0101 | 1 1 1 | 0111 | ||
6 | 0110 | 1 0 1 | 0101 | ||
7 | 0111 | 1 0 0 | 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 |
If see the above definition of reflective code that is 'n' least significant bits for through are the mirror images of those for 0 through .
So,
Here in this above example n = 4 (4 - bit binary number), so, to means to i.e. 8 to 15 and 0 to is 0 to i.e. 0 to 7.
So, all 4th least significant bits of 8 to 15 are the mirror images of those codes for 0 to 7.
When considering 3 bit, then n = 3,
So, all 3rd least significant bits of 4 to 8 are the mirror images of those codes for 0 to 3.
Related