The below examples illustrate how to perform the Binary to Grey Code conversion and Grey Code to Binary conversion.
Binary to Gray Code Conversion
Consider b1, b2, b3, b4 and b5 is the Binary Number and it is need be converted into Grey Code.
1. Write Most Significant Bit (MSB) is same as the MSB in Binary Number.
2. The second bit of the Grey code can be found by performing the Exclusive-OR (EX-OR) operation between the First and second bits of the Binary Number.
3. The Third bit of the Grey code can be found by performing the Exclusive-OR (EX-OR) operation between the Third and Second bits of the given Binary Number; and so on
EX-OR Operation: 1. Both the bits are 0 or 1 then the output of EX-OR gate will be 0.
2. Any one of the bit in two bits is 1 then the output of EX-OR gate will be 1.
Refer the below image for Binary to Gray Code Conversion
Gray Code to Binary Conversion
Consider g0, g1, g2 and g3 is the Grey Code and it is need be converted into Binary Number. The steps for Binary to Grey Code Conversion needs to be reversed to find out the equivalent Binary Number
1. The Most Significant Bit (MSB) of the Binary is same as the First MSB of the Grey Code.
2. If the second Grey Bit is 0 then the second bit of the Binary is bit will be same as that of the First Binary bit; if the Second Gry Bit is 1 then the Second Bit of the Binary will be inverse of its previous binary bit. Refer the below image for easy understanding of Grey to Binary Conversion