Saturday 20 July 2013



Gray code

Gray Code Wheel

“The reflected binary code is called Gray code after the name of Frank Gray.”
·         4 bit code.
·         Contains 0-15 decimal numbers.
Decimal
Binary
Gray code
0
0000
0000
1
0001
0001
2
0010
0011
3
0011
0010
4
0100
0110
5
0101
0111
6
0110
0101
7
0111
0100
8
1000
1100
9
1001
1101
10
1010
1111
11
1011
1110
12
1100
1010
13
1101
1011
14
1110
1001
15
1111
1000

   Binary to Gray code conversion

To convert a binary number to Gray code, apply following steps;

Step 1:
 left most bit of gray code and its corresponding binary code is same.
Step2:
going from left to right, add each adjacent pair of binary digit to get the next gray code digit, regardless carries.
e.g convert binary number (0100)2 to gray code.
Step1:
             0    1    0    0       (binary code of 4)
             ↓
             0
Step2:
            0 +  1    0     0
            ↓      ↓
            0      1
Step3:
             0      1   +   0     0
             ↓       ↓       ↓
             0      1        1
Step4:
             0       1       0  +   0
             ↓       ↓        ↓        ↓
             0       1        1       0     (Gray code)

 Gray code to binary conversion

It has following steps.
Step1:
 write down left most bit of gray code as it is same in binary code.
Step2:
 going from left to write, add last single bit of binary into next bit of gray code then write down the answer and continue till last bit.
e.g convert gray code (0101) into binary code.
Step1:
             0     1     0    1
             ↓
             0
Step2:
             0     1      0      1
             ↓ +  ↓
             0           1

Steo3:
                   0       1          0       1
                   ↓        ↓    +    ↓
                   0        1          1
Step4:
                  0       1       0       1
                  ↓       ↓        ↓   +  ↓

                  0        1       1       0      

0 comments :

Post a Comment