Jump to content

Talk:Gray code

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Zundark (talk | contribs) at 15:29, 26 February 2003 (text from Gray_coding). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

The following was at Gray_coding, and is moved here in case anyone wants to add some of it to the Gray_code article.


A gray code is a special coding system designed to prevent spurious output from practical electromechanical switches and is specifically relevant to encoding of position information for a rotating object. For example, if we create a device that indicates position by closing and opening switches, we could use the binary code to represent position:

Binary Code
Input position Output 3 Output 2 Output 1
0 0 0 0
1 0 0 1
2 0 1 0
3 0 1 1
4 1 0 0
5 1 0 1
6 1 1 0
7 1 1 1

The problem is that, with real (mechanical) switches, it is very unlikely that two switches will change states exactly in synchrony. For example, in the transistion from state 3 to state 4, all three switches change state. In the brief period while all are changing, the switches will read some spurious position.

A gray code solves this problem by changing only one switch at a time, so there is never any ambiguity of position:

Gray Code
Input position Output 3 Output 2 Output 1
0 0 0 0
1 0 0 1
2 0 1 1
3 0 1 0
4 1 1 0
5 1 1 1
6 1 0 1
7 1 0 0

Notice also that state seven can roll over to state zero with only one switch change.