Day 4 of RTL codes
Gray to Binary Code Conversion
Gray to Binary Code Conversion
• Gray to Binary Code Conversion Basics:
• To convert Gray code back to binary, use a
cumulative XOR approach.
• The MSB of the binary code is the same as the
MSB of the Gray code.
• Each following binary bit is found by XORing the
previous binary bit with the current Gray code bit.
• Conversion Rule:
• For a 4-bit Gray code G3 G2 G1 G0 :
o B3=G3
o B2=B3⊕G2
o B1=B2⊕G1
o B0=B1⊕G0
• Example of Conversion:
• Given a Gray code G3 G2 G1 G0 use the conversion
formulae to find each binary bit.
Aravind Madapati
Madapatiaravind268@[Link]
9618641406
Day 4 of RTL codes
• Truth Table for 4-bit Gray to Binary Conversion:
Gray (G) Binary (B)
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
Aravind Madapati
Madapatiaravind268@[Link]
9618641406
Day 4 of RTL codes
• Circuit Diagram for Gray to Binary Code
Conversion:
• Use XOR gates to implement the Gray-to-binary
conversion.
Fig: Gray code to Binary code conversion
• Connect each Gray input bit according to the
conversion rule:
o B3=G3
o B2=B3⊕G2
o B1=B2⊕G1
o B0=B1⊕G0
• Design Steps:
• Identify Gray code inputs.
• Apply XOR gates based on the conversion
formulae.
• Output binary bits based on the XOR gate outputs.
Aravind Madapati
Madapatiaravind268@[Link]
9618641406
Day 4 of RTL codes
Gray Code to Binary Conversion
Design, Test Bench and Waveform.
Fig: Gray Code to Binary Design code
Fig: Gray Code to Binary code Test Bench
Aravind Madapati
Madapatiaravind268@[Link]
9618641406
Day 4 of RTL codes
Fig: Waveform
Aravind Madapati
Madapatiaravind268@[Link]
9618641406