Convert a decimal number straight to Gray code – first to binary, then one XOR pass. Handy for encoder positions and Karnaugh-map orderings.
Show calculation steps
Processed privately in your browser — nothing you paste is uploaded, logged or stored.
Position numbers, straight to Gray
Encoder positions, state indices and K-map cells arrive as decimals; their Gray patterns are two exact steps away — decimal to binary by repeated division, then the XOR pass. This page chains both with each stage visible.
The composition is worth internalising: Gray code is a PERMUTATION of binary counting, so every decimal has exactly one Gray pattern of its bit length.
Worked example
Decimal: 11 Stage 1: 11 → binary 1011 Stage 2: 1011 → Gray 1110 (11 in the 4-bit table: row 11 reads 1011 / 1110 ✓)
| Decimal | Binary | Gray |
|---|---|---|
| 0 | 0000 | 0000 |
| 1 | 0001 | 0001 |
| 2 | 0010 | 0011 |
| 3 | 0011 | 0010 |
| 4 | 0100 | 0110 |
| 5 | 0101 | 0111 |
| 6 | 0110 | 0101 |
| 7 | 0111 | 0100 |
| 8 | 1000 | 1100 |
| 9 | 1001 | 1101 |
| 10 | 1010 | 1111 |
| 11 | 1011 | 1110 |
| 12 | 1100 | 1010 |
| 13 | 1101 | 1011 |
| 14 | 1110 | 1001 |
| 15 | 1111 | 1000 |
Reflected construction, briefly
The n-bit Gray sequence is the (n−1)-bit sequence followed by its mirror image, with 0s prefixed to the first half and 1s to the second. The mirroring is what makes the seam step — and the wraparound — single-bit. “Reflected binary code”, Frank Gray’s 1947 patent name, describes the build literally.
Uses at the decimal end
Programming an absolute encoder’s expected readings, generating test sequences for counters, labelling K-map axes, and building lookup tables for FPGA cross-domain counters — each starts from decimal indices and lands in Gray, exactly this page’s route.
Privacy
Both stages compute locally; your numbers never leave the page.
How to use the Decimal to Gray Code Converter
- Enter a non-negative decimal number.
- Click "Convert to Gray".
- The steps show the two stages: decimal to binary, then the XOR pass to Gray.
- Use the table generator to see your value in sequence context.
Frequently asked questions
What are the two stages of this conversion?
Decimal → binary by repeated division, then binary → Gray by g = b ⊕ (b >> 1). For 11: binary 1011, Gray 1110. Each stage is shown separately in the steps for your number.
Why go straight from decimal at all?
Convenience when working from position counts: an encoder disk position, a state number in a sequence design, or a Karnaugh-map cell index arrives as a decimal – one page instead of two hops.
Is Gray code unique for each number?
Yes – reflected binary Gray code is a bijection: every non-negative integer has exactly one Gray pattern of its bit length, and the mapping is reversible without loss.
Why is it called "reflected" binary code?
The n-bit sequence is built by mirroring the (n−1)-bit sequence and prefixing 0s then 1s: the reflection is what guarantees the single-bit-change property, including at the mirror seam.
Do negative decimals have Gray codes?
Not in the standard code – it is defined over non-negative indices. Encoding a signed value requires choosing a binary representation first (e.g. two's complement), after which the XOR pass applies mechanically.
How do I get back to decimal from Gray?
Gray → binary with the cascade decoder, then binary → decimal by place values: two exact steps, both available as dedicated pages linked below.
Is my number kept anywhere?
No – both stages compute in the page; nothing is transmitted or logged.