4.3.1 Defining the requirements

We start by defining the requirements. For a Gray encoder, we want to the output to comply with Gray code characteristics. Let's define a code as a list of codewords, where a codeword is a bit string. A code of order n has 2**n codewords.

A well-known characteristic is the one that Gray codes are all about:

Requirement 1   Consecutive codewords in a Gray code should differ in a single bit.

Is this sufficient? Not quite: suppose for example that an implementation returns the lsb of each binary input. This would comply with the requirement, but is obviously not what we want. Also, we don't want the bit width of Gray codewords to exceed the bit width of the binary codewords.

Requirement 2   Each codeword in a Gray code of order n must occur exactly once in the binary code of the same order.

With the requirements written down we can proceed.

About this document