Convert reflected Gray code back to weighted binary by cascading XOR from the top bit down – each binary bit is the XOR of the previous binary bit with the current Gray bit.
Show calculation steps
Processed privately in your browser β nothing you paste is uploaded, logged or stored.
Cascading back to weighted binary
Decoding Gray requires a cascade: the top binary bit equals the top Gray bit, and each further binary bit is the PREVIOUS binary bit XOR the current Gray bit. The dependency chain is the structural difference from encoding, whose XORs are independent.
Software reading encoder hardware performs exactly this loop; the steps panel exposes it bit by bit for your pattern.
Worked example
Gray: 1110 b1 = g1 = 1 b2 = b1βg2 = 1β1 = 0 b3 = b2βg3 = 0β1 = 1 b4 = b3βg4 = 1β0 = 1 Binary: 1011 (decimal 11)
| 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 |
Why the cascade cannot be parallelised naively
Each output bit consumes the previous OUTPUT β a serial dependency. Hardware decoders either chain XOR gates (delay grows with width) or use prefix-XOR tricks to regain speed; software just loops. Understanding the dependency is what separates memorising the formula from owning it.
Verification habits
Encode-decode must round-trip: push the result through Binary to Gray Code and the original pattern must reappear. The table above lets you spot-check any 4-bit pair on sight β the two columns convert into each other by the two rules.
Privacy
Decoding is local; nothing is transmitted.
How to use the Gray Code to Binary Converter
- Enter the Gray-coded bits.
- Click "Convert to binary".
- The steps show the cascade: each binary bit is the previous binary bit XOR the current Gray bit.
- The decimal value of the recovered binary is shown for confirmation.
Frequently asked questions
How does decoding differ from encoding?
Encoding XORs neighbouring INPUT bits independently; decoding must cascade, because each binary bit depends on the previously RECOVERED bit: b[i] = b[i-1] β g[i]. That serial dependency is why decode circuits chain XORs.
Walk me through decoding 1110 back to binary?
Keep the top bit: b1 = 1. Then cascade: b2 = b1 β g2 = 1β1 = 0; b3 = b2 β g3 = 0β1 = 1; b4 = b3 β g4 = 1β0 = 1. Result: 1011, which is decimal 11. The steps panel performs exactly this cascade on whatever you enter.
Why would data arrive Gray-coded in the first place?
Because a sensor or FIFO pointer produced it that way for glitch immunity. Software reading an encoder register typically receives Gray and must decode before any arithmetic – exactly this operation.
Does double-decoding or double-encoding cycle back?
Encode and decode are inverse permutations: encode(decode(g)) = g and decode(encode(b)) = b. Applying the SAME operation twice does not return the original – the pair are distinct functions, unlike ROT13-style codes.
Can I decode a value with leading zeros?
Yes – leading zeros decode to leading zeros and the value is unaffected; width is preserved so fixed-width registers stay honest.
What is the largest pattern this handles?
Arbitrary length – the cascade is linear and exact, so 64-bit and longer encoder values decode without any precision concern.
Processed locally?
Yes – the XOR cascade runs in your browser only.