Industrial Training




Grey Code in Digital Electronics

Similar to Excess-3 Code, Grey Codes are unweighted codes i.e. these codes are not positionally weighted. In a weighted code, a fixed value or weight is assigned to each position with in a binary number. This is not the case with unweighted codes.

Now, let’s say bits of a 4 bit binary number from right are denoted by b0, b1, b2, b3 and corresponding bits in grey code representation are denoted by g0, g1, g2, g3. Grey code equivalent of the given binary number is computed as follows:

g3 = b3
g2 = b3 βŠ• b2
g1 = b2 βŠ• b1
g0 = b1 βŠ• b0

Here, βŠ• is a symbol for XOR. For a quick reference below is the truth table of XOR:

A B XOR
0 0 0
0 1 1
1 0 1
1 1 0

Let’s understand this by taking an example. To find the grey code equivalent of 5, first convert it into binary format i.e. 0101 and then compute the equivalent as below:

g3 = b3 = 0
g2 = b3 βŠ• b2 = 0 βŠ• 1 = 1
g1 = b2 βŠ• b1 = 1 βŠ• 0 = 1
g0 = b1 βŠ• b0 = 0 βŠ• 1 = 1

Thus grey code equivalent of 5 is 0111. Below is the table displaying grey code equivalent of decimal numbers (0-7):

Decimal Number Binary Number Grey Code Equivalent
0 0000 0000
0 0001 0001
2 0010 0011
3 0011 0010
4 0100 0110
5 0101 0111
6 0110 0101
7 0111 0100


Converting from Grey to Binary


b3 = g3
b2 = b3 βŠ• g2
b1 = b2 βŠ• g1
b0 = b1 βŠ• g0

Thus, binary equivalent of 1101 (grey code) can be computed as follows:

b3 = g3 = 1
b2 = b3 βŠ• g2 = 1 βŠ• 1 = 0
b1 = b2 βŠ• g1 = 0 βŠ• 0 = 0
b0 = b1 βŠ• g0 = 0 βŠ• 1 = 1

Thus, binary equivalent of 1101 is 1001.

Grey code is also known as reflected code as three of the bits are reflected as it is and only one bit will change on going from one step to the next. Thus, advantage of using grey codes is that between any two consecutive numbers, only one bit gets changed at a time and that reduces the possibility of errors. Grey code, therefore, belongs to a class of codes called minimum change codes.



Hi I am Pluto.