Skip to content

Gray code ​

Sometimes, two values close together have an equivalent binary representation that look totally different. Gray code try to fix this issue.

Quick example

ValueBitsGray
701110100
810001100
The 4-bits representation of 7 and 8 look very different. With Gray code, only 1 bit change, allowing a better representation of the gaps between real values.

Note: the difference between two sequence of bits is the Hamming distance. In this example, 7 and 8 are at a bit-distance of 4, but only of 1 with Gray code.