Gray Code Converter

Decimal to Gray Code Converter

Convert a non-negative decimal integer to reflected binary Gray code. See the ordinary binary representation, right-shifted binary value, XOR operation, Gray code result, and step-by-step conversion.

✓ Decimal Input ✓ Binary Conversion ✓ XOR Method ✓ Gray Code Output ✓ Free Unlimited Use
10→G
Decimal → Gray Code
● Ready
Enter a non-negative whole decimal number such as 5, 10, 25, or 255.
Try:
✓ Gray Code Result
Reflected binary Gray code
Decimal 0
Binary 0
Gray Bits 0
Conversion Breakdown

What Is Decimal to Gray Code Conversion?

Decimal to Gray code conversion changes an ordinary base-10 integer into its reflected binary Gray code representation. Gray code uses only 0 and 1, but its ordering differs from ordinary binary.

A useful property of reflected Gray code is that adjacent values differ by only one bit.

Decimal to Gray Code Formula

For a non-negative integer N, its Gray code value can be calculated with:

Gray = N XOR (N >> 1) where: N = original number N >> 1 = number shifted right by one bit XOR = exclusive OR

How to Convert Decimal to Gray Code

1. Start with decimal

Enter the non-negative decimal integer you want to encode.

2. Convert it to binary

Find the ordinary base-2 representation of the decimal number.

3. Shift binary right

Create a second value by shifting the original binary number one position right.

4. Align both values

Keep the shifted value aligned with the original bit positions.

5. XOR the bits

Apply XOR between the original binary number and its right-shifted version.

6. Read the Gray code

The XOR result is the reflected binary Gray code.

Example: Convert Decimal 10 to Gray Code

Decimal: 10 Convert decimal 10 to binary: 10₁₀ = 1010₂ Shift right by one position: 1010 >> 1 = 0101 Apply XOR: 1010 XOR 0101 —— 1111 Therefore: Decimal 10 = Gray Code 1111

Example: Convert Decimal 5 to Gray Code

Decimal 5 in binary: 101 Right shift: 010 XOR: 101 XOR 010 = 111 So: 5₁₀ = 111 Gray

Decimal to Gray Code Table

Decimal Binary Gray Code
000000000
100010001
200100011
300110010
401000110
501010111
601100101
701110100
810001100
910011101
1010101111
1110111110
1211001010
1311011011
1411101001
1511111000

Why Does Gray Code Change One Bit at a Time?

In the standard reflected Gray-code sequence, consecutive encoded integers differ in exactly one bit position. For example, decimal 2 has Gray code 0011, while decimal 3 has Gray code 0010.

Only the final bit changes between those two Gray values. This property is useful when several binary signals cannot be guaranteed to switch at exactly the same instant.

Decimal, Binary and Gray Code

System Purpose Example for Decimal 10
Decimal Base-10 numeric notation 10
Binary Base-2 numeric representation 1010
Gray Code Single-bit-transition encoding 1111

Why Use XOR for Decimal to Gray Conversion?

The expression N XOR (N >> 1) compares each binary bit with its neighboring higher-order bit. XOR produces 1 when those aligned bits differ and 0 when they are the same.

That operation directly creates the reflected Gray-code representation of the integer.

Where Is Gray Code Used?

Gray code is commonly discussed in digital electronics, rotary and linear encoders, Karnaugh maps, hardware counters, position sensing, and systems where reducing ambiguity during state transitions is useful.

It is an encoding scheme rather than a replacement for ordinary binary arithmetic.

Common Decimal to Gray Code Mistakes

Reading binary as Gray code

Binary and Gray code both contain 0 and 1, but their encoded values are not generally identical.

Using OR instead of XOR

Standard binary-reflected Gray conversion specifically requires XOR.

Shifting in the wrong direction

The formula uses the original number shifted one bit to the right.

Using decimal digits directly

Gray encoding is derived from the binary representation of the decimal integer.

Important: this calculator uses standard binary-reflected Gray code for non-negative whole integers. Negative values and custom Gray-code variants may require a separate encoding convention.

Related BinaryCon Tools

Decimal to Gray Code Converter FAQs

How do you convert decimal to Gray code?
Convert the decimal integer to binary, shift that binary value one position right, and XOR the original value with the shifted value.
What is the formula for decimal to Gray code?
For integer N, the standard formula is Gray = N XOR (N >> 1).
What is decimal 2 in Gray code?
Decimal 2 is binary 10. Its standard Gray code is 11.
What is decimal 5 in Gray code?
Decimal 5 is binary 101. XORing it with 010 gives Gray code 111.
What is decimal 10 in Gray code?
Decimal 10 is binary 1010. XOR with 0101 gives Gray code 1111.
What is decimal 0 in Gray code?
Decimal 0 is represented as Gray code 0.
Is Gray code the same as binary?
No. Both use binary digits, but Gray code follows an encoding where consecutive values differ by one bit.
Why is Gray code called reflected binary code?
A standard Gray-code sequence can be constructed recursively by reflecting an existing sequence and adding leading bits, which gives it the name reflected binary code.
Can large decimal integers be converted?
Yes. This calculator uses integer arithmetic rather than ordinary 32-bit JavaScript bitwise conversion for the main calculation.
Does Gray code preserve the decimal value when read as ordinary binary?
No. A Gray code bit pattern should be decoded as Gray code, not interpreted directly as an ordinary binary integer.
What is the reverse of decimal to Gray code conversion?
You can decode the Gray code back to binary and then interpret the binary value as decimal. BinaryCon’s Gray Code to Decimal Converter performs that operation.
Does BinaryCon require registration?
No. The Decimal to Gray Code Converter can be used directly without signup.
Scroll to Top