- Asked 3/22
- 2078 Bhadra · 1.5 marks
- 2076 Chaitra · 3 marks
- 2074 Chaitra · 2 marks
Gray code with examples
Short answer
Gray code is an unweighted binary code where successive values differ by only one bit. Example: decimal 0–3 in 3-bit Gray are 000, 001, 011, 010. Conversion keeps MSB and each next Gray bit equals XOR of adjacent binary bits; used in encoders to prevent false readings.
Explain Gray code with suitable examples.
Gray code is an unweighted binary code in which two successive numbers differ in only one bit. It is also called the reflected binary code or a unit-distance code.
4-bit Gray code table
| Decimal | Binary | Gray | Decimal | Binary | Gray |
|---|---|---|---|---|---|
| 0 | 0000 | 0000 | 8 | 1000 | 1100 |
| 1 | 0001 | 0001 | 9 | 1001 | 1101 |
| 2 | 0010 | 0011 | 10 | 1010 | 1111 |
| 3 | 0011 | 0010 | 11 | 1011 | 1110 |
| 4 | 0100 | 0110 | 12 | 1100 | 1010 |
| 5 | 0101 | 0111 | 13 | 1101 | 1011 |
| 6 | 0110 | 0101 | 14 | 1110 | 1001 |
| 7 | 0111 | 0100 | 15 | 1111 | 1000 |
Binary to Gray
MSB stays the same; each next Gray bit = XOR of the current and previous binary bits: .
Example: → G = 1, 1⊕0 = 1, 0⊕1 = 1, 1⊕1 = 0 → .
Gray to binary
MSB stays the same; each next binary bit = previous binary bit XOR current Gray bit: .
Example: → B = 1, 1⊕1 = 0, 0⊕1 = 1, 1⊕0 = 1 → .
Uses
- Shaft position (rotary) encoders: only one bit changes per step, so no false reading at transitions.
- K-map labelling (00, 01, 11, 10).
- Reducing switching errors in counters and ADCs.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Digital signal and Gray code · Digital Logic, chapter 1 · asked 2×
- Digital IC signal levels and Gray code · Digital Logic, chapter 1 · asked 2×
- 3-bit Gray code synchronous counter · Digital Logic, chapter 8 · asked 2×
- BCD code and 3-bit binary-to-Gray converter · Digital Logic, chapter 1
- Gray code and 3-bit binary-to-Gray converter · Digital Logic, chapter 1
- Gray vs binary code, convert (10110)₂ to Gray · Digital Logic, chapter 1