Use 32-bit or 64-bit architecture.
Gray code, or reflected binary code, is a binary numbering system where two consecutive values differ in only one bit. Named after researcher Frank Gray, it stops digital and mechanical systems from reading wrong intermediate values when numbers change.
In digital electronics, a Gray code counter is a specialized circuit where only one bit changes state with every clock pulse. Unlike standard binary counters—where multiple bits can flip simultaneously (e.g., 011 to 100 flips three bits)—a Gray code counter eliminates temporary glitches, race conditions, and high dynamic power consumption during state transitions.
Key Properties:
What is a gray code and how (and why) is it used? (In your own words.)
Develop and test three functions:
Create a reasonable amount of test test data.
Print the input and output and make it "pretty".
Gray code (Wikipedia)
How To Convert Gray Code to Binary and Binary to Gray Code (YouTube)
Gray Code (Geeks for Geeks)
| Decimal | Binary | Gray | Decimal | Binary | Gray |
|---|---|---|---|---|---|
| 0 | 0000 | 0000 | 8 | 1000 | 1100 |
| 1 | 0001 | 0001 | 9 | 1001 | 1101 |
| 2 | 0010 | 0011 | 10 | 1010 | 1111 |
| 3 | 0011 | 0010 | 11 | 1011 | 1110 |
| 4 | 0100 | 0110 | 12 | 1100 | 1010 |
| 5 | 0101 | 0111 | 13 | 1101 | 1011 |
| 6 | 0110 | 0101 | 14 | 1110 | 1001 |
| 7 | 0111 | 0100 | 15 | 1111 | 1000 |
Note: For decimal 15 the code rolls over to decimal 0 with only one switch change. This is called the cyclic or adjacency property of the graycode. (Wikipedia)