Gray Code
Gray Code
A Gray code is an encoding of numbers so that adjacent numbers have a single digit differing by 1.
The term Gray code is often used to refer to a "reflected" code, or more specifically still, the binary reflected
Gray code.
The reflected binary code or Gray code is an ordering of the binary numeral system such that two
successive values differ in only one bit (binary digit). Gray codes are very useful in the normal sequence of
binary numbers generated by the hardware that may cause an error or ambiguity during the transition from
one number to the next. So, the Gray code can eliminate this problem easily since only one bit changes its
value during any transition between two numbers.
Gray code is not weighted that means it does not depends on positional value of digit. This cyclic
variable code that means every transition from one value to the next value involves only one bit change.
Gray code also known as reflected binary code, because the first (n/2) values compare with those of
the last (n/2) values, but in reverse order.
0 0 00 00 000 000
1 1 01 01 001 001
10 11 010 011
11 10 011 010
100 110
101 111
110 101
111 100
0 000 000
1 001 001
2 010 011
3 011 010
4 100 110
5 101 111
6 110 101
7 111 100
Types of Gray Codes
There are also other types of Gray codes, like Beckett-Gray code, Single track Gray codes etc.
N-ary Gray code, where non-Boolean values are included like sequences of 1, 2, 3.
Two dimensional (n,k) Gray codes are used for error correction.
Balanced Gray codes has equal transition counts.
Uses of Gray codes
Gray codes are used in rotary and optical encoders, Karnaugh maps, and error detection.