ARTICLE CONTENT · UPDATED 14 JAN, 2026
CODE CONVERSION
Code Converters - Binary to/from Gray Code
Code Converters are digital combinational circuits that translate data representation from one format to another. This article covers the concepts, truth tables, K-maps, Boolean expressions, and logic circuits for converting binary code to Gray code and vice versa.
1. What are Code Converters?
Code Converters are digital circuits or algorithms designed to translate data representation from one format to another format. The binary-to-Gray code converter takes binary input and translates it into its corresponding Gray code representation.
What is Binary Code?
Binary code is the numerical system used in digital electronics consisting of symbols 0 and 1. Each bit position represents a power of 2 starting from the rightmost bit (20, 21, 22 ...). It serves as the basis for encoding text and numbers in digital systems.
What is Gray Code?
Gray Code is an unweighted binary system where every successive pair of numbers differs by only one bit. It eliminates multi-bit switching errors when hardware transitions between states.
Alternative Names for Gray Code:
Unit Hamming Distance Code
Cyclic Code
Reflecting Code
2. Converting Binary to Gray Code
Let b0, b1, b2, b3 be the binary bits (b0 = LSB, b3 = MSB) and g0, g1, g2, g3 be the Gray code bits (g0 = LSB, g3 = MSB).
Truth Table
| Binary (b3b2b1b0) |
Gray Code (g3g2g1g0) |
| 0000 | 0000 |
| 0001 | 0001 |
| 0010 | 0011 |
| 0011 | 0010 |
| 0100 | 0110 |
| 0101 | 0111 |
| 0110 | 0101 |
| 0111 | 0100 |
| 1000 | 1100 |
| 1001 | 1101 |
| 1010 | 1111 |
| 1011 | 1110 |
| 1100 | 1010 |
| 1101 | 1011 |
| 1110 | 1001 |
| 1111 | 1000 |
K-Map Simplifications
K-Map for g3
| b1,b0b3,b2 |
00 | 01 | 11 | 10 |
| 00 | 0 | 0 | 0 | 0 |
| 01 | 0 | 0 | 0 | 0 |
| 11 | 1 | 1 | 1 | 1 |
| 10 | 1 | 1 | 1 | 1 |
K-Map for g2
| b1,b0b3,b2 |
00 | 01 | 11 | 10 |
| 00 | 0 | 0 | 0 | 0 |
| 01 | 1 | 1 | 1 | 1 |
| 11 | 0 | 0 | 0 | 0 |
| 10 | 1 | 1 | 1 | 1 |
K-Map for g1
| b1,b0b3,b2 |
00 | 01 | 11 | 10 |
| 00 | 0 | 0 | 1 | 1 |
| 01 | 0 | 0 | 1 | 1 |
| 11 | 0 | 0 | 1 | 1 |
| 10 | 0 | 0 | 1 | 1 |
K-Map for g0
| b1,b0b3,b2 |
00 | 01 | 11 | 10 |
| 00 | 0 | 1 | 0 | 1 |
| 01 | 0 | 1 | 0 | 1 |
| 11 | 0 | 1 | 0 | 1 |
| 10 | 0 | 1 | 0 | 1 |
Minimized Boolean Expressions
-
g3 = b3
MSB bit passes through directly.
-
g2 = b3'b2 + b3b2' = b3 ⊕ b2
-
g1 = b2'b1 + b2b1' = b2 ⊕ b1
-
g0 = b1'b0 + b1b0' = b1 ⊕ b0
Logic Circuit (Binary to Gray)
3. Converting Gray Code to Binary
Converting Gray code back to binary uses feedback logic from the calculated binary outputs:
Truth Table
| Gray Code (g3g2g1g0) |
Binary (b3b2b1b0) |
| 0000 | 0000 |
| 0001 | 0001 |
| 0011 | 0010 |
| 0010 | 0011 |
| 0110 | 0100 |
| 0111 | 0101 |
| 0101 | 0110 |
| 0100 | 0111 |
| 1100 | 1000 |
| 1101 | 1001 |
| 1111 | 1010 |
| 1110 | 1011 |
| 1010 | 1100 |
| 1011 | 1101 |
| 1001 | 1110 |
| 1000 | 1111 |
K-Map Simplifications
K-Map for b3
| g1,g0g3,g2 |
00 | 01 | 11 | 10 |
| 00 | 0 | 0 | 0 | 0 |
| 01 | 0 | 0 | 0 | 0 |
| 11 | 1 | 1 | 1 | 1 |
| 10 | 1 | 1 | 1 | 1 |
K-Map for b2
| g1,g0g3,g2 |
00 | 01 | 11 | 10 |
| 00 | 0 | 0 | 0 | 0 |
| 01 | 1 | 1 | 1 | 1 |
| 11 | 0 | 0 | 0 | 0 |
| 10 | 1 | 1 | 1 | 1 |
K-Map for b1
| g1,g0g3,g2 |
00 | 01 | 11 | 10 |
| 00 | 0 | 0 | 1 | 1 |
| 01 | 1 | 1 | 0 | 0 |
| 11 | 0 | 0 | 1 | 1 |
| 10 | 1 | 1 | 0 | 0 |
K-Map for b0
| g1,g0g3,g2 |
00 | 01 | 11 | 10 |
| 00 | 0 | 1 | 0 | 1 |
| 01 | 1 | 0 | 1 | 0 |
| 11 | 0 | 1 | 0 | 1 |
| 10 | 1 | 0 | 1 | 0 |
Minimized Boolean Expressions
-
b3 = g3
-
b2 = b3 ⊕ g2 = g3 ⊕ g2
-
b1 = b2 ⊕ g1 = g3 ⊕ g2 ⊕ g1
-
b0 = b1 ⊕ g0 = g3 ⊕ g2 ⊕ g1 ⊕ g0
Logic Circuit (Gray to Binary)
4. Applications of Code Converters
-
Rotary Encoders
Translates shaft rotation angles to digital signals. Gray code eliminates read errors during mechanical state changes.
-
Control Systems
Interfaces subsystems operating between binary controllers and Gray-coded hardware sensors.
-
Signal Processing
Minimizes bit transmission errors across digital communication channels.
-
Analog-to-Digital Converters (ADCs)
Serves as a reliable interface between Gray-coded ADC outputs and binary digital processing systems.