# Digital Logic: Binary to Gray Code Converter

Before starting with this read Digital Logic: Designing Decimal to 4 bit Gray Code Converter if you are unfamiliar.

##### Binary, Decimal and Gray Code Table:

Here I am representing gray code bits with A, Decimal values with D and Binary bits with B.

 Binary Decimal Gray Code B3 B2 B1 B0 D A3 A2 A1 A0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 2 0 0 1 1 0 0 1 1 3 0 0 1 0 0 1 0 0 4 0 1 1 0 0 1 0 1 5 0 1 1 1 0 1 1 0 6 0 1 0 1 0 1 1 1 7 0 1 0 0 1 0 0 0 8 1 1 0 0 1 0 0 1 9 1 1 0 1 1 0 1 0 10 1 1 1 1 1 0 1 1 11 1 1 1 0 1 1 0 0 12 1 0 1 0 1 1 0 1 13 1 0 1 1 1 1 1 0 14 1 0 0 1 1 1 1 1 15 1 0 0 0
##### Binary to Gray Code Converter:

This same technique can be applied to make gray to binary converter. There will be 4 input bits, which represent binary and 4 output bits which represent equivalent gray code.

Since we are creating binary to gray code converter so, we need to find expressions for each gray code output in terms of input binary bits.

So, there will be four output bits $A_3, A_2, A_1, A_0$. For these output bits the input will be different combinations of $B_3, B_2, B_1, B_0$ based on minimized expression.

## A3:

Minimized expression from the above k map,
$A_3 = B_3$

## A2:

Minimized expression from the above k map,
$A_2 = B_3 \overline{B_2} + B_2 \overline{B_3}$

But, the expression of XOR Gate is (Let, A and B be the inputs),
$A.\overline{B} + B.\overline{A} = A \oplus B$
[Note: This is not related to this problem but, only showing how XOR can be made from And, Or, Not gates]

Similarly,it can be shown that,
$B_3 \overline{B_2} + B_2 \overline{B_3} = B_2 \oplus B_3$

If XOR gate is not available then the former expression can be used with and, or and not gates to design the gray code converter.

## A1:

Minimized expression from the above k map,
$A_1 = B_1 \overline{B_2} + B_2 \overline{B_1}$

Similarly,it can be shown that,
$B_1 \overline{B_2} + B_2 \overline{B_1} = B_1 \oplus B_2$

## A0:

Minimized expression from the above k map,
$A_0 = B_0 \overline{B_1} + B_1 \overline{B_0}$

Similarly,it can be shown that,
$B_0 \overline{B_1} + B_1 \overline{B_0} = B_0 \oplus B_1$