Gray Code to Decimal Converter
Convert Gray code (reflected binary) to decimal numbers online. Each Gray code value is decoded to its decimal equivalent.
Paste a column of Gray code values and get back the decimal numbers, one per line. Flip on the binary intermediate if you want to see the XOR-chain step sitting between the two — useful when you're debugging a rotary encoder reading or double-checking a Karnaugh map. And everything runs in your browser. Nothing gets uploaded.
How to Use
Enter Gray code values in the left panel, one per line. You can type, paste, or click Sample for example data.
Optionally enable "Show binary intermediate" to see the binary step between Gray code and decimal conversion.
Click Convert or leave Live mode enabled for real-time conversion as you type.
Copy, Download, or Swap the result. Swap converts decimal values back to Gray code.
Frequently Asked Questions
What is Gray code?
Gray code (also called reflected binary code) is a binary numeral system where two successive values differ in only one bit. It was invented by Frank Gray and is widely used in rotary encoders, error correction, Karnaugh maps, and digital communications. For example, the decimal sequence 0, 1, 2, 3 in standard binary is 00, 01, 10, 11, but in Gray code it is 00, 01, 11, 10.
How does Gray code to decimal conversion work?
The conversion happens in two steps. First, the Gray code is converted to standard binary: the most significant bit stays the same, and each subsequent binary bit is computed by XOR-ing the previous binary bit with the current Gray code bit. Then the resulting binary number is converted to decimal using normal base-2 arithmetic. For example, Gray code 1101 becomes binary 1001, which equals decimal 9.
Why is Gray code used instead of standard binary?
Gray code minimizes errors during transitions because only one bit changes at a time. In standard binary, transitioning from 7 (0111) to 8 (1000) requires all four bits to change simultaneously, which can cause transient incorrect values. Gray code avoids this by ensuring single-bit transitions, making it ideal for mechanical encoders, analog-to-digital converters, and position sensors.
What does the "Show binary intermediate" option do?
When enabled, the output shows the intermediate binary value alongside the decimal result for each Gray code input. This is helpful for learning and verifying the conversion process. For example, instead of just showing "9", it will display "1101 -> 1001 -> 9" so you can see the Gray-to-binary step clearly.
Can I convert decimal numbers back to Gray code?
Yes. Click the Swap button to switch the output into the input panel, which automatically changes the mode to decimal-to-Gray-code. The tool will parse the decimal values (one per line) and convert them back to their Gray code representations by first converting to binary, then applying the binary-to-Gray algorithm (XOR each bit with the bit above it).