57. Gray to Binary Code Converter

Design a combinational logic circuit to convert a 4-bit Gray code input into a 4-bit Binary output.

Constraints:

  • Inputs: Gray code lines (G3, G2, G1, G0)
  • Outputs: Binary lines (D3, D2, D1, D0)
  • Components: Must build everything from scratch using basic gates only. Ready-made converter blocks are forbidden.

Behavioral Reference:

G3G2G1G0D3D2D1D0
00000000
00010001
00110010
00100011
01100100
01110101
01010110
01000111
11001000
11011001
11111010
11101011
10101100
10111101
10011110
10001111
Need Help? Refer to the Quick Guide below

Code conversion circuits change digital data from one code representation to another while preserving the represented value.

Input Code → Combinational Converter → Output Code

Code Reference Tables

For decimal digits 0–9, Binary and BCD use the same 4-bit patterns.

DecimalBinaryBCDGrayExcess-3Hex
000000000000000110
100010001000101001
200100010001101012
300110011001001103
401000100011001114
501010101011110005
601100110010110016
701110111010010107
810001000110010118
910011001110111009

Decimal 10–15

Binary, Gray, and Hex use a single 4-bit/digit representation; BCD and Excess-3 encode each decimal digit separately.

DecimalBinaryBCDGrayExcess-3Hex
1010100001 000011110100 0011A
1110110001 000111100100 0100B
1211000001 001010100100 0101C
1311010001 001110110100 0110D
1411100001 010010010100 0111E
1511110001 010110000100 1000F

Binary and BCD Conversion

For a single decimal digit 0–9, 4-bit Binary and BCD use the same bit pattern, so no conversion logic is required. For values greater than 9, BCD encodes each decimal digit separately.

Decimal 5: Binary = 0101, BCD = 0101
Decimal 12: Binary = 1100, BCD = 0001 0010

Binary and Gray Conversion

Binary-to-Gray

Copy the MSB directly. XOR each pair of adjacent input bits.

G3 = B3
G2 = B3 ⊕ B2
G1 = B2 ⊕ B1
G0 = B1 ⊕ B0
Binary 0010 → Gray 0011
Binary to Gray converter using a direct MSB path and three XOR gates

Gray-to-Binary

Copy the Gray MSB directly. Generate each remaining output bit by XORing the previous output bit with the next Gray bit.

B3 = G3
B2 = B3 ⊕ G2
B1 = B2 ⊕ G1
B0 = B1 ⊕ G0
Gray 0011 → Binary 0010
Gray to Binary converter using cascaded XOR gates from MSB to LSB

BCD and Excess-3 Conversion

Excess-3 represents each decimal digit by adding binary 0011 (decimal 3) to its corresponding 4-bit BCD value.

BCD + 0011 → Excess-3
Excess-3 − 0011 → BCD

BCD-to-Excess-3

Excess-3 = BCD + 0011
0011 + 0011 = 0110

For BCD inputs B3_B2_B1_B0, define:

X = B1 + B0

E3 = B3 + B2 · X
E2 = B2 ⊕ X
E1 = (B1 ⊕ B0)'
E0 = B0'
BCD to Excess-3 converter using minimized combinational logic

Excess-3-to-BCD

BCD = Excess-3 − 0011

0110 − 0011 = 0011

For inputs E3_E2_E1_E0, define:

Y = E1 · E0

B3 = E3 · (E2 + Y)
B2 = (E2 ⊕ Y)'
B1 = E1 ⊕ E0
B0 = E0'
Excess-3 to BCD converter using minimized combinational logic

BCD-to-7-Segment Decoder

A BCD-to-7-segment decoder converts a BCD digit 0–9 into seven control signals a–g used to display the corresponding decimal digit. The following uses an active-HIGH common-cathode display.

Seven-segment display diagram showing segment labels a, b, c, d, e, f, and g
Common-cathode display: 1 = Segment ON, 0 = Segment OFF

7-segment code order: a b c d e f g

DecimalBCDabcdefg
000001111110
100010110000
200101101101
300111111001
401000110011
501011011011
601101011111
701111110000
810001111111
910011111011

Minimized Active-HIGH Segment Equations

a = B1 + B3 + B2 · B0 + B2' · B0'
b = B2' + B1 · B0 + B1' · B0'
c = B0 + B2 + B1'
d = B3 + B1 · B0' + B1 · B2' + B2' · B0' + B2 · B0 · B1'
e = B1 · B0' + B2' · B0'
f = B3 + B2 · B0' + B2 · B1' + B1' · B0'
g = B3 + B1 · B0' + B1 · B2' + B2 · B1'

Note: BCD inputs 1010–1111 are unused for decimal digits and may be treated as don't-care conditions when simplifying the logic.

BCD-to-7-Segment Circuit

BCD 0011 (3) → 7-Segment 1111001
Active-HIGH BCD-to-7-segment decoder driving a common-cathode display.

Note: For a common-anode display, the segment-control logic is inverted: 0 = Segment ON and 1 = Segment OFF.