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:
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.