13-2. Incrementing a Gray-Coded Integer

The logic for incrementing a 4-bit binary integer abcd can be expressed as follows, using Boolean algebra notation:

Thus, one way to build a Gray-coded counter in hardware is to build a binary counter using the above logic, and convert the outputs a′, b′, c′, d′ to Gray by forming the exclusive or of adjacent bits, as shown under “Gray from Binary” in Figure 13-1.

A way that might be slightly better is described by the following formulas:

That is, the general case is

Because the parity p alternates between ...

Get Hacker's Delight now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.