Gray code is also an encoding method that can be used for counting. It only changes one bit when adding 1, which simplifies hardware implementation. Therefore, many speed sensors, absolute position sensors and so on will use Gray code count. In addition, due to the characteristics of Ray codes, a change process only changes one bit. Compared with the normal binary count, the increase of 1 May change Multiple Digits, which is more secure. Therefore, it is safer and easier to implement the State count of the state machine in the digital circuit.
Gray code can be generated as follows
0: Image 0 + symbol 00: Image 00 + symbol 000 .....
1 1 01 01 001
---------
1 11 11 011
0 10 10 010
-----------------
10 110
11 111
01 101
00 100
Relationship between Gray code and binary code
A binary number is BnBn-1Bn-2... b1b0
A gray code is GnGn-1Gn-2... g1g0
Binary to Gray code:
Highest bit:
GN = Bn
Other BITs gi = (Bi + 1) ^ (BI );
Gray code to binary:
Highest bit:
BN = Gn
Other BITs Bi = (Bi + 1) ^ (GI );