Understanding Grey Code Conversion
Grey Code is a binary numeral system where two successive values differ in only one bit. This "unit distance" property makes it vital for digital systems to prevent data errors during transitions.
1. The Foundation: XOR Truth Table
The conversion process relies on the XOR (Exclusive OR) operation. Think of it as a "difference detector."
| Input A | Input B | Output (A ⊕ B) |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
2. Binary to Grey Conversion
The Rule:
- The MSB (Most Significant Bit) remains the same.
- For every other bit, XOR the current binary bit with the bit to its left.
Visual Example: Binary 1011 to Grey
Binary: 1 → 0 → 1 → 1
↓ ⊕ ⊕ ⊕
Grey: 1 1 1 0
↓ ⊕ ⊕ ⊕
Grey: 1 1 1 0
3. Grey to Binary Conversion
The Rule:
- The MSB remains the same.
- For every other bit, XOR the previously calculated binary bit with the current Grey bit.
Visual Example: Grey 1110 to Binary
Grey: 1 1 1 0
↓ ↗ ⊕ ↗ ⊕ ↗ ⊕
Binary: 1 0 1 1
↓ ↗ ⊕ ↗ ⊕ ↗ ⊕
Binary: 1 0 1 1
Developer's Shortcut: In programming, you can convert Binary to Grey using: G = B ^ (B >> 1)