• missing xbfish.com image

Tag Archives: binary

Conversion of Binary & Gray codes

First of all, you need to understand the truth table for Exclusive-OR gate:

Input Output
0 0 0
0 1 1
1 0 1
1 1 0

With this in mind, we move on to converting binary code to gray code.

Suppose we want to convert decimal 10, binary value of 1010 to gray code, the first step is to retain the most significant bit(MSB) of the binary. Hence,

1 0 1 0 (binary)
1 x x x (gray)

where x is still unknown.

Then, we take the adjacent pair of binary code to derive the 2nd significant bit of the gray code. Based on the truth table, 1 and 0 give us a 1 :

1 0 1 0 (binary)
1 1 x x (gray)

Then we move on to the next adjacent pair of binary code to get the 3rd significant bit of the gray code, with reference from the OR truth table :

1 0 1 0 (binary)
1 1 1 x (gray)

and lastly,

1 0 1 0 (binary)
1 1 1 1 (gray)

Therefore, the gray code of 1010 (decimal 10) is 1111.

Now, to convert gray code to binary code, we employ the same technique with the exception that we take the previous significant bit of the gray code and the next binary code to get the output.

Suppose we want to convert decimal 6, gray code value of 0101 to binary code, the first step is still to retain the MSB of the binary. Hence,
0 1 0 1 (gray)
0 x x x (binary)

where x is still unknown.

From here, we move on to take the previous significant bit of the gray code and the next binary code, which is 1 and 0. 1 and 0 give us 1.

0 1 0 1 (gray)
0 1 x x (binary)

and then we move on….

0 1 0 1 (gray)
0 1 1 x (binary)

0 1 0 1 (gray)
0 1 1 0 (binary)

Thus, the binary code of 0101 (decimal 6 in binary) is 0110.