Gray code and binary code converted into gray code

Source: Internet
Author: User

In the code of a group of numbers, if any two adjacent code is different from only one binary number, it is said that this code is gray code (gray code), gray code is composed of 0 and 1, the binary code evolved.

The Gray code generation method is as follows:

    1. 1-bit gray code with two code words
    2. (n+1) Bit gray code in the first 2n code word equal to n-bit gray code word, in order to write, prefixed by 0
    3. (n+1) Bit gray code in the following 2n code word equals n-bit gray code word, in reverse order, plus prefix 1

Examples are as follows:

1-bit Gray code:

0

1

2-bit Gray code:

A total of 2^2 code word, the first half of the code word for 1-bit Gray code in order to write the prefix 0, the second half of the code word for 1-bit gray code reverse writing prefix 1, the results are as follows:

00

01

11

10

3-bit gray code is:

Based on the 2-bit gray code, the results are as follows:

000

20s

011

010

110

111

101

100

In the same vein, n-bit gray code can be obtained.

Binary conversion into Gray code:

The principle is that the highest bit of the binary code is retained as the highest bit of the Gray code, the second highest bit of the Gray code is the binary coded maximum and the sub-high difference or, the other bits of the gray code and the second high of the method similar.

Binary code:1011 to be converted to gray Code

1011 = 1 (according to the first digit), 1 (First and second XOR 1^0 = 1), 1 (second or third digit, 0^1=1), 0 (1^1 =0) = 1110

Actually equals (1011 >> 1) ^ 1011 = 1110

Gray code and binary code converted into gray code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.