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:
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.
With the requirements written down we can proceed.
About this document