The Gray code is an unweighted digital code. Its main property is that two successive words in the code only differ in one bit, eliminating spurious states; advantage is taken of this coding adjacency to simplify the functions.
It is also called reflected binary code, and is simple to construct: Start at the right (the nth digit, dn). If its neighbour on its left, digit dn-1 is a 1, replace dn by 1-dn; otherwise leave it unchanged. Continue to the left, applying the same rules to each digit. The last digit d1 is kept the same since it is assumed to be a 0.
Example with 4 bits: