Gray Code Converter (Decimal ⇄ Binary ⇄ Gray Code)
Convert between decimal, binary and Gray code with instant three-way boxes — runs 100% in your browser, nothing is uploaded.
🔒 Converted in your browser — nothing is uploaded.
What Gray code is
Gray code, also called reflected binary code, is an ordering of binary numbers in which any two successive values differ in exactly one bit. That single-bit-change property makes it valuable for rotary encoders, position sensors and state machines, where a glitchy multi-bit transition in ordinary binary could momentarily read a completely wrong value. Converting binary to Gray code is a simple bitwise operation: the first bit stays the same, and every other Gray bit is the XOR of the current binary bit with the one before it, which is the same as computing b XOR (b shifted right by one).
Using this converter
Type a decimal number, a binary string, or a Gray code and the other two boxes update live — so you can go decimal → Gray directly (the way encoder positions and textbook exercises are framed) or decode a Gray value straight back to a plain number. Each field updates the others as you type. Binary to Gray applies g[i] = b[i-1] XOR b[i] per position, and Gray to binary reverses it with a cumulative XOR, so b[i] = b[i-1] XOR g[i]. Only the digits 0 and 1 are accepted, and any other character shows a clear message. Leading zeros are preserved, so an 8-bit pattern stays 8 bits wide.
Frequently asked questions
How do I convert binary to Gray code by hand?
Keep the most significant bit as-is, then XOR each remaining binary bit with the bit to its left. For example 1011 becomes 1110: the leading 1 stays, then 1⊕0=1, 0⊕1=1 and 1⊕1=0. This tool does exactly that for you as you type.
How do I convert Gray code back to binary?
The first bit is copied unchanged, then each following binary bit is the XOR of the previous binary bit with the current Gray bit — a running cumulative XOR. So 1110 decodes back to 1011. Just type into the Gray code box and the binary result appears instantly.
Is my input uploaded to a server?
No. Every conversion runs locally in your browser with JavaScript. Nothing you type is sent, stored or uploaded anywhere.