This is a variable weighted code and is cyclic. This means that it is arranged so that every transition from one value to the next value involves only one bit change. The Gray code is sometimes referred to as reflected binary, because the first eight values compare with those of the last 8 values, but in reverse order.

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 |

__Modulo 2 Arithmetic__This is binary addition with the carry ignored.

__Converting Gray Code to Binary__1. write down the number in gray code

2. the most significant bit of the binary number is the most significant bit of the gray code

3. add (using modulo 2) the next significant bit of the binary number to the next significant bit of the gray coded number to obtain the next binary bit

4. repeat step 3 till all bits of the gray coded number have been added modulo 2

the resultant number is the binary equivalent of the gray number

Example, convert 1101101 in gray code to binary

Gray Binary

1101101

**1**101101 1 copy down the msb

1

**1**01101

**1**0 1 modulo2 1 = 0

11

**0**1101 1

**0**0 0 modulo2 0 = 0

110

**1**101 10

**0**1 0 modulo2 1 = 1

1101

**1**01 100

**1**0 1 modulo2 1 = 0

11011

**0**1 1001

**0**0 0 modulo2 0 = 0

110110

**1**10010

**0**1 0 modulo2 1 = 1

the answer is 1001001

__Converting Binary to Gray__1. write down the number in binary code

2. the most significant bit of the gray number is the most significant bit of the binary code

3. add (using modulo 2) the next significant bit of the binary number to the next significant bit of the binary number to obtain the next gray coded bit

4. repeat step 3 till all bits of the binary coded number have been added modulo 2

the resultant number is the gray coded equivalent of the binary number

Example, convert 1001001 in binary code to gray code

Binary Gray

1001001

**1**001001 1 copy down the msb

**10**01001 11 1 modulo2 0 = 1

1

**00**1001 110 0 modulo2 0 = 0

10

**01**001 1101 0 modulo2 1 = 1

100

**10**01 11011 1 modulo2 0 = 1

1001

**00**1 110110 0 modulo2 0 = 0

10010

**01**1101101 0 modulo2 1 = 1

The answer is 1101101

__Excess 3 Gray Code__In many applications, it is desirable to have a code that is BCD as well as unit distance. A unit distance code derives its name from the fact that there is only one bit change between two consecutive numbers. The excess 3 gray code is such a code, the values for zero and nine differ in only 1 bit, and so do all values for successive numbers.

Outputs from linear devices or angular encoders may be coded in excess 3 gray code to obtain multi-digit BCD numbers.

Decimal Excess 3 Gray

0 0010

1 0110

2 0111

3 0101

4 0100

5 1100

6 1101

7 1111

8 1110

9 1010

## 0 Comments