Gray code is a binary code. The difference between adjacent Gray codes is only one bit, that is, the Hamming distance is 1. Generation method: Write down the Gray code [0, 1] of length 1. Invert the Gray code of length n-1 and append it to the end. Add 0 before the sequence generated in step 2 to connect the sequence of step 2 and step 3.
The rules of Gray code
Gray code is a binary code that has the following properties: continuous The two Gray codes differ only in one bit. That is, in Gray code, the Hamming distance between two adjacent codes is 1.
Generate Gray code
The method of generating Gray code is as follows:
Example
Generate Gray code with length 3:
Application
Gray code has applications in many fields, such as:
The above is the detailed content of What are the rules of Gray code?. For more information, please follow other related articles on the PHP Chinese website!