Calculators
Gray Code Calculator
Convert binary to reflected Gray code and Gray code to binary with exact bit strings and preserved leading zeros.
Convert binary digits to reflected Gray code or decode Gray code to binary. Enter up to 4096 bits. Leading zeros and bit width are preserved; all processing stays in your browser.
How reflected Gray code conversion works
Reflected binary Gray code orders integers so adjacent values differ in one bit at a fixed width. To encode binary, keep the first bit and XOR each remaining bit with the preceding input bit: G = B XOR (B shifted right by one). To decode, keep the first Gray bit, then XOR each next Gray bit with the previously decoded binary bit. Binary 1011 encodes to Gray 1110, which decodes back to binary 1011 (decimal 11). Leading zeros are preserved: binary 0011 becomes Gray 0010. The decimal result always refers to the binary value, not to interpreting the Gray digits as an ordinary binary number. Zero and one-bit inputs are supported. Enter 1 to 4096 digits containing only 0 and 1; surrounding whitespace is accepted, but internal spaces, signs and 0b prefixes are rejected. This calculator uses standard reflected binary Gray code, not other Gray code variants. Calculations run entirely in your browser.
Frequently Asked Questions
Everything you need to know about this tool, how it works, and privacy.
How do I convert binary to Gray code?
Keep the first bit, then XOR each binary bit with the preceding binary bit. Binary 1011 becomes Gray 1110.
How do I decode Gray code?
Keep the first bit, then XOR each Gray bit with the previously decoded binary bit. Gray 1110 becomes binary 1011, or decimal 11.
Are leading zeros preserved?
Yes. Input and output have the same width. Binary 0011 becomes Gray 0010.
What input is supported?
Enter 1 to 4096 bits using only 0 and 1. Surrounding whitespace is accepted. Prefixes, internal whitespace and signs are rejected.
Why use Gray code?
Adjacent values in the reflected Gray sequence differ by one bit at a fixed width. This property is useful in encoders and digital logic.