What Is the Gray Code?

The typical binary Gray code (Binary Gray Code) is referred to as the Gray code. It was named after the "Pulse Code Communication" patent of Frank Gray (18870913-19690523) published in 1953. It was originally used for communication. -Digital conversion and position-Digital conversion in progress. French telecommunications engineer Jean-Maurice-Émile Baudot (18450911-19030328) used a baud code equivalent to a variant of it. An 8-element binary mechanical counter designed by George Stibitz in 1941 coincided with the counting law of Gray code counters.

In the encoding of a group of numbers, if any two adjacent codes have only one digit binary number, this encoding is called Gray Code, and because there is only one digit between the maximum and minimum numbers Different, that is, "end to end", so it is also called cyclic code or reflection code . [2]
Gray codes have multiple encoding forms
Decimal 4-bit natural binary code 4-digit typical Gray code
Decimal Remaining Gray Code
Decimal empty six gray code Decimal Six Jump Gray Code Step code
0
0000
0000
0010
0000
0000
00000
1
0001
0001
0110
0001
0001
00001
2
0010
0011
0111
0011
0011
00011
3
0011
0010
0101
0010
0010
00111
4
0100
0110
0100
0110
0110
01111
5
0101
0111
1100
1110
0111
11111
6
0110
0101
1101
1010
0101
11110
7
0111
0100
1111
1011
0100
11100
8
1000
1100
1110
1001
1100
11000
9
1001
1101
1010
1000
1000
10000
10
1010
1111
----
----
----
----
11
1011
1110
----
----
----
----
12
1100
1010
----
----
----
----
13
1101
1011
----
----
----
----
14
1110
1001
----
----
----
----
15
1111
1000
---- ---- ---- ----
Typical Gray codes in the table are representative. Unless otherwise specified, Gray codes refer to typical Gray codes , which can be converted from natural binary codes.
  • Gray code is a reliability code , which is a kind of error minimization
    The French engineer Jean-Maurice- & Eacute; mlle Baudot used the Baud code in 1880 as a variant of the typical Gray code. [3]
    According to the characteristics of Gray code, that is, for two adjacent decimal numbers, the corresponding two Gray codes differ only by one binary bit. In addition, there is only one binary bit difference between the maximum and minimum numbers. The following is a Gray code c implementation that uses a binary number of length n to represent the decimal number m. The running result is shown in the right figure:
     #include <stdio.h> voidmain () {intm, n, i, j, b, p, bound; intgr [14]; // Enter n, m and determine whether m is legal bound = 1; printf ("Pleaseinputtwonumber: n, m \ n "); scanf ("% d,% d ", & n, & m); for (i = 1; i <= n; i ++) bound * = 2; if (m <0 || m> = bound) {printf ("Dataerror!"); exit (0);} b = 1; for (i = 0; i <n; i ++) {p = 0; b * = 2; for (j = 0; j <= m; j ++) {if (j% bb / 2 == 0) p = 1-p;} gr [i] = p;} printf ("m ="); for (i = n-1; i> = 0; i--) {printf ("% d", gr [i]);} printf ("\ n");} 
    Pascal program for Gray code decoding:
      var
     x, y, i: longint;
     begin
     readln (x);
     fori: = 30downto0do
     begin
     y: = (xand (1shli)) xor ((xand (1shl (i + 1))) shr1);
     x: = xandnot (1shli) ory;
     end;
     writeln (x);
     end.
     2
     var
     x, i, n: longint;
     begin
     readln (n);
     x: = n;
     fori: = 1to31do
     begin
     x: = xshr1;
     n: = nxorx;
     end;
     writeln (n);
     end.
    

    IN OTHER LANGUAGES

Was this article helpful? Thanks for the feedback Thanks for the feedback

How can we help? How can we help?