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.
- 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 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 empty six gray code | Decimal Six Jump Gray Code | Step code |
---|---|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| ---- | ---- | ---- | ---- |
- 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.