Decimal to Gray Code Converter
Convert decimal to Gray code (binary), live as you type.
Gray code is a binary numbering system where consecutive values differ by exactly one bit — used in rotary encoders and error correction to avoid glitches from multiple bits flipping at once. Converts live as you type, entirely in your browser.
Need the opposite? Gray Code to Decimal Converter
What is Decimal to Gray Code Converter?
Gray code is a binary numbering system where consecutive values differ by exactly one bit, used in rotary encoders, Karnaugh maps, and error correction to avoid glitches from multiple bits flipping at once during a transition. Type a decimal number and get its Gray code equivalent instantly, with optional bit-width padding so the output lines up at a fixed length across a batch of values. Multiple values are supported at once, which is useful when you're building a lookup table or verifying a sequence rather than converting one number at a time. Conversion happens live as you type, entirely in your browser. Nothing is sent to a server.
Decimal to Gray Code Chart (0-15)
| Decimal | Gray Code |
|---|---|
| 0 | 0000 |
| 1 | 0001 |
| 2 | 0011 |
| 3 | 0010 |
| 4 | 0110 |
| 5 | 0111 |
| 6 | 0101 |
| 7 | 0100 |
| 8 | 1100 |
| 9 | 1101 |
| 10 | 1111 |
| 11 | 1110 |
| 12 | 1010 |
| 13 | 1011 |
| 14 | 1001 |
| 15 | 1000 |
How to Use the Decimal to Gray Code Converter
- 1
Enter a Decimal Number: Type one or more non-negative whole numbers, for example 12 or 25.
- 2
Set a Bit Width (Optional): Pad the output to a fixed number of bits if you need every result to line up for a lookup table.
- 3
Read the Gray Code Result Instantly: The Gray code equivalent appears automatically, with no button to click.
- 4
Copy the Result: Use the copy button to copy the Gray code value for use in hardware design, coursework, or documentation.
How Decimal Converts to Gray Code
First convert the decimal number to regular binary. Then, starting from the leftmost (most significant) bit, each Gray code bit is the XOR of that binary bit with the binary bit immediately to its left (the leftmost Gray bit is just copied from binary unchanged, since there's no bit to its left). The result is a code where every consecutive decimal value differs from the last by exactly one bit.
How to Convert Decimal to Gray Code
Converting 12: first, 12 in binary is 1100. Line the bits up and XOR each bit with the one before it. The first Gray bit (1) is copied as-is, then 1 XOR 1 = 0, 0 XOR 0 = 0, 0 XOR 0 = 0, giving Gray code 1010. As a check: 11 in Gray code is 1110, and 1010 (12) differs from 1110 (11) by exactly one bit (the second position), confirming the one-bit-change property.
Examples
5 → binary 0101 → Gray code 0111
25 → binary 11001 → Gray code 10101
8 → binary 1000 → Gray code 1100Frequently Asked Questions
Common questions about Decimal to Gray Code Converter.