How Gray Are The Gray Codes?

Many data acquisition systems and rotary encoders use the Gray Codes for their operation. As only one bit changes state while the numbers progress, read errors from timing and mechanical issues are minimized. Initially, use of Gray Codes was limited to specific applications, but now this versatile coding scheme is extensively used in Karnaugh maps, error detection systems, and in rotary and optical encoders.

In general, a Gray Code represents numbers using the binary encoding scheme and it groups a sequence of bits such that only one bit in the group changes from the number before and after it. Frank Gray, a researcher from Bell Labs, described the code in his 1947 patent, where he called it the Binary Reflected Code. After the patent was granted in 1953, the encoding system was referred to as the Gray Code.

Being an un-weighted code, the columns of bits in the Gray Code do not imply any base weight in contrast to the Binary number system. For instance, in the Binary number system, the right most column holds the most significant bit and carries a weight of 20=1; the second column has the weight of 21=2; the third 22=4, and so on. That means each column represents a base (2 in Binary) raised to a power, with the final value calculated by multiplying the bit by the weight of its column and adding the results of the columns.

Although columns in the Gray Code are also positional, they are not weighted, as the Gray Code is a numeric representation of a cyclic encoding scheme. The code rolls over and repeats, therefore, it is unsuitable for mathematical operations. To be used in displays or in mathematical computations, Gray Code sequences need to be converted to Binary or Binary Coded Decimal (BCD).

Gray Codes are a member of unit-distant, minimal-change codes. That means only a single bit of the sequence changes with the progress of the number count. Therefore, Gray Codes are more flexible during synchronization and misalignment as they limit the maximum read error to one unit. This property makes them useful in error detection schemes as well. Communication systems use Gray Codes in preference to parity check, as detection of unexpected changes in data is better with Gray Codes. If you sum up the bits in a number, the sum of the next number will change only by one, with the sum alternating even and odd.

Rapidly changing values can lead to errors due to interfacing or hardware constraints. This is where the Gray Code is most useful, as only a single bit quantifies the change. That is also the reason most mechanical rotary and optical encoders offer Gray Code outputs. However, Gray Codes have progressed farther than the encoding mask that Frank Gray documented in his patent.

For example, aircrafts use mechanical altimeters where the encoding disk is synchronized to the dials, producing a sort of Gray Code output known as the Gillham Code. The specialized code offers a single-bit change for each increment of 100 feet – allowing an easy tracking of the altitude.