Binary ,Gray Code Conversion

Binary and Gray Code Conversion


Gray code is a type of unit distance code. In unit distance code the bit patterns for two consecutive numbers will differ in one bit position. We can also say it as Cyclic codes.

Binary to Gray Code Conversion

Follow the below Steps to convert Binary number to gray code.
Lets Consider The Binary number B1 B2 B3 B4 ... Bn and the Gray code is G1 G2 G3 G4 ... Gn
  1. Most significant bit (B1) is same as the most significant bit in Gray Code (B1 = G1)
  2. To find next bit perform Ex-OR (Exclusive OR) between the Current binary bit and previous bit.
    Gn = Bn (Ex-OR) Bn-1
  3. Look the below Image for Binary to Gray code Conversion
    Binary to Gray Code Conversion


Gray Code to Binary Conversion

Follow the below steps to convert Gray Code to Binary
  1. Most significant bit (G1) is same as the most significant bit in Binary Code (G1 = B1)
  2. The next number can be obtain by taking Exclusive OR operation between the previous binary bit, and the current gray code bit and write down the value.
  3. Repeat the Above Step until you find Bn

Look at the below example for Converting Binary to Gray Code.
Gray Code to Binary Conversion
Similar Worksheets