Gray Code to Decimal Converter
Convert reflected binary Gray code directly to decimal. Enter a Gray code such as 1111 to recover its ordinary binary value, see the XOR decoding process, and calculate the exact decimal integer.
What Is Gray Code to Decimal Conversion?
Gray code to decimal conversion decodes a reflected binary Gray code sequence into ordinary binary and then interprets that binary value as a base-10 integer.
Gray code cannot normally be read directly as an ordinary binary number because the same bit string may represent a different numerical value under Gray-code rules.
How to Convert Gray Code to Decimal
1. Start with Gray code
Write the Gray-code bits from left to right.
2. Copy the first bit
The first ordinary binary bit is identical to the first Gray bit.
3. Apply XOR
XOR the previous binary result with the next Gray bit.
4. Continue across all bits
Each new binary bit depends on the previous decoded binary bit.
5. Read the binary value
After processing every Gray bit, you have the ordinary binary representation.
6. Convert binary to decimal
Interpret the decoded binary sequence as a base-2 integer.
Gray Code to Binary Rule
If the Gray bits are represented by G and the decoded binary bits
by B, the first bit is:
After the binary sequence is recovered, ordinary positional binary conversion gives the decimal value.
Example: Convert Gray Code 1111 to Decimal
Example: Convert Gray Code 111 to Decimal
Gray Code to Decimal Table
| Gray Code | Binary | Decimal |
|---|---|---|
0000 | 0000 | 0 |
0001 | 0001 | 1 |
0011 | 0010 | 2 |
0010 | 0011 | 3 |
0110 | 0100 | 4 |
0111 | 0101 | 5 |
0101 | 0110 | 6 |
0100 | 0111 | 7 |
1100 | 1000 | 8 |
1101 | 1001 | 9 |
1111 | 1010 | 10 |
1110 | 1011 | 11 |
1010 | 1100 | 12 |
1011 | 1101 | 13 |
1001 | 1110 | 14 |
1000 | 1111 | 15 |
Why Can’t Gray Code Be Converted Directly Like Binary?
Ordinary binary digits have positional weights such as 1, 2, 4, 8, and 16. Gray code does not use that same direct positional interpretation.
The Gray bits must first be decoded into ordinary binary before base-2 place values can be used to calculate the decimal integer.
Gray Code vs Binary Value
| Bit Pattern | If Read as Binary | If Read as Gray |
|---|---|---|
1111 |
15 | 10 |
111 |
7 | 5 |
11 |
3 | 2 |
The encoding convention therefore matters when interpreting the bits.
Why Is XOR Used?
In Gray decoding, each ordinary binary bit tells you the accumulated relationship between earlier Gray bits. XOR provides exactly the required rule:
Starting with the copied first bit, applying XOR repeatedly recovers the original binary sequence.
Gray Code Applications
Gray code is commonly associated with rotary encoders, position sensors, digital circuits, Karnaugh maps, counters, and systems where limiting transitions between neighboring encoded states can reduce ambiguity.
Can Long Gray Codes Be Converted?
Yes. The conversion algorithm works from left to right using simple XOR logic, so the binary bit string itself can be decoded without relying on ordinary 32-bit JavaScript bitwise arithmetic.
The final binary value is then interpreted using integer arithmetic to produce the decimal result.
Common Gray Code to Decimal Mistakes
Reading Gray directly as binary
Gray bits must be decoded before applying ordinary binary positional weights.
XORing adjacent Gray bits
Each new binary bit uses the previous decoded binary bit and current Gray bit.
Changing the first bit
The most significant binary bit is copied directly from the first Gray bit.
Using OR instead of XOR
Gray-code decoding requires exclusive OR, not ordinary OR.
Related BinaryCon Tools
Gray Code to Decimal Converter FAQs
How do you convert Gray code to decimal?
What is Gray code 11 in decimal?
11 decodes to binary 10, which equals decimal 2.
What is Gray code 111 in decimal?
111 decodes to binary 101, which equals decimal 5.
What is Gray code 1111 in decimal?
1111 decodes to binary 1010, so its decimal value is 10.
Is Gray code 1111 equal to decimal 15?
1111 were interpreted as ordinary binary.
As Gray code it represents decimal 10.