Gray Code: What is it? And How to Convert Binary to Gray Code
Gray code is a sequence of binary number systems, which is also known as, reflected binary code because the first N/2 values compared with those of the last N/2 values in reverse order. In gray code two consecutive values are differed by one bit of binary digits. The application of gray code is encoders, altimeters, and Karnaugh maps (K-Map) due to their error detection and unit-distant properties. In gray code the only one bit change in transition between two successive code.
WHAT IS GRAY CODE?
Gray code is the arrangement of binary number system such that each incremental value can only differ by one bit. This code is also known as Reflected Binary Code (RBC), Cyclic Code and Reflected Binary (RB). In gray code when transverse from one step to another step the only one bit will be change of the group. This means that the two adjacent code numbers differ from each other by only one bit.
BINARY TO GRAY CODE CONVERSION EXAMPLE
We have some binary number 010.01 which we wish to convert to gray code. Let us see the step how to convert binary to gray code?
- The first MSB bit of binary is same in the first bit of gray code. In this example the binary bit is “0”. So, gray bit also “0”.
- Next gray bit is equal to the XOR of the first and the second binary bit. The first bit is 0, and the second bit is 1. The bits are different so resultant gray bit will be “1” (second gray codes bit)
- The XOR of the second and third binary bit. The second bit is 1 and third is 0. These bits are again different so the resultant gray bit will be 1 (third gray codes bit)
- Next we perform the XOR operation on third and fourth binary bit. The third bit is 0, and the fourth bit is 0. The both bits are same than resultant gray codes will be 0 (fourth gray codes bit).
- Take the XOR of the fourth and fifth binary bit. The fourth bit is 0 and fifth bit is 1. These bits are different than resultant gray codes will be 1 (fifth gray code bit)
- The result of binary to gray codes conversion is 01101.
for more information you can search on google — Gray code knowelectronic