Free digital logic calculator

Gray Code to Binary Converter

Decode reflected Gray code into ordinary binary in seconds. Enter a Gray code bit string to get the binary equivalent, inspect every cumulative XOR operation, and preserve leading zeros for fixed-width digital values.

Convert Gray Code to Binary

Enter a Gray code using only 0 and 1. Spaces and underscores are optional.

Enter a reflected binary Gray code. Maximum input length: 4,000 bits, excluding spaces and underscores.

Conversion result

Binary output
Original Gray code

Step-by-step cumulative XOR

The first binary bit equals the first Gray bit. Each following binary bit is the XOR of the previous binary bit and the current Gray bit.

What Is Gray Code to Binary Conversion?

Gray code, also called reflected binary code, is a binary encoding in which adjacent values in the standard sequence differ by exactly one bit. It is used in digital electronics, rotary encoders, position sensors, and some hardware control systems.

Gray code is not the same as ordinary binary. To recover the conventional binary representation, you must decode the Gray bits using cumulative exclusive OR (XOR).

The Gray code to binary formula

Copy the most significant Gray bit directly to the first binary position. Then calculate every following binary bit using the previous binary bit and the current Gray bit.

B₀ = G₀ Bᵢ = Bᵢ₋₁ XOR Gᵢ

XOR returns 0 when its two input bits are the same and 1 when they are different. Because each binary bit depends on the previous binary bit, the conversion proceeds from left to right.

Example: Convert Gray code 1110 to binary

Position Gray bit Calculation Binary bit
11Copy first bit1
211 XOR 1 = 00
310 XOR 1 = 11
401 XOR 0 = 11

The result is binary 1011. In decimal, this binary number represents 11.

Why does cumulative XOR work?

In reflected Gray code, each Gray bit after the first indicates whether the corresponding binary bit differs from the preceding binary bit. If the Gray bit is 0, the binary bit remains the same. If the Gray bit is 1, the binary bit changes.

XOR performs exactly this operation, allowing each binary bit to be reconstructed in sequence.

Gray code and binary comparison table

Decimal value Gray code Binary equivalent
000000000
100010001
200110010
300100011
401100100
501110101
601010110
701000111
811001000
911011001
1011111010
1111101011
1210101100
1310111101
1410011110
1510001111

Where is Gray code used?

Gray code is useful when a system needs to identify transitions between neighboring states. Examples include rotary encoders that measure angular position and digital systems that use Gray-coded counters or state representations.

Since adjacent values in the standard Gray sequence differ by one bit, a transition can be less ambiguous than a binary transition where several bits change together. Gray code does not eliminate every timing or synchronization problem, but it can help reduce transition ambiguity in suitable designs.

Leading zeros are preserved. For example, Gray code 0011 converts to binary 0010, not 10. Keeping the same bit width is often important when working with digital hardware and test vectors.

Frequently Asked Questions

How do I convert Gray code to binary?

Copy the first Gray bit. For each remaining bit, XOR the current Gray bit with the previous binary output bit. Join the resulting bits to get the binary representation.

What is Gray code 1110 in binary?

Gray code 1110 converts to binary 1011, which represents decimal 11.

What is Gray code 1111 in binary?

Gray code 1111 converts to binary 1010, which represents decimal 10.

What is the difference between Gray code and binary?

Ordinary binary uses positional powers of two. Reflected Gray code rearranges the bit patterns so consecutive values differ by only one bit. A Gray code must be decoded to recover its ordinary binary representation.

Does this calculator preserve leading zeros?

Yes. It preserves the number of bits in the input, so fixed-width values remain fixed-width after conversion.

Can I enter spaces between Gray code bits?

Yes. Spaces and underscores are ignored. The remaining input must contain only 0 and 1.

Can Gray code be converted to decimal?

Yes. First decode Gray code into ordinary binary, then convert that binary number to decimal. The related binary-to-decimal calculator below can perform the second step.

Is Gray code suitable for ordinary arithmetic?

Gray code is primarily an encoding scheme rather than a positional arithmetic system. For addition, subtraction, and other standard arithmetic operations, decode it to ordinary binary first.

Related Binary and Digital Logic Tools

Continue exploring number-system conversions and digital logic calculators on Binarios.org.