Convert standard binary to Gray code (reflected binary) with step-by-bit XOR operations
Input Binary
Result
Gray Code
Step-by-Step Derivation
Binary to Gray Principle
Gray₀ = Binary₀ (MSB copy)
Gray₁ = Binary₁ XOR Binary₀
Gray₂ = Binary₂ XOR Binary₁
Grayₙ = Binaryₙ XOR Binaryₙ₋₁
Binary to Gray conversion: copy the MSB, then each subsequent Gray bit is current binary bit XOR previous binary bit.
⚠Binary must contain only 0s and 1s. No other characters allowed.
What Is Binary to Gray Conversion?
Binary to Gray code conversion is straightforward: copy the most significant bit, then compute each subsequent Gray bit as the XOR of the current and previous binary bits.
MSB Copied
The most significant bit of Gray code is the same as binary: Gray₀ = Binary₀.
XOR Operation
Each subsequent Gray bit = current binary bit XOR previous binary bit.
Single Bit Change
Resulting Gray code has only one bit changing between consecutive numbers.
Easy to Compute
The conversion requires only bitwise operations, making it efficient in hardware and software.
1. The leftmost bit of Gray = leftmost bit of binary. 2. Each subsequent Gray bit = current binary bit XOR previous binary bit. 3. Continue until all bits are processed.
What is binary to Gray code formula?▼
Gray₀ = Binary₀, Gray₁ = Binary₁ XOR Binary₀, Gray₂ = Binary₂ XOR Binary₁, Grayₙ = Binaryₙ XOR Binaryₙ₋₁. Each Gray bit is XOR of current and previous binary bit.
Why convert binary to Gray code?▼
Gray code ensures only one bit changes between consecutive numbers, which prevents ambiguous intermediate states in sensors, encoders, and digital systems.
What is the Gray code for 5 (101 binary)?▼
Gray₀ = 1, Gray₁ = 0 XOR 1 = 1, Gray₂ = 1 XOR 0 = 1. Result = 111. Verify: consecutive numbers change only one bit (4=110, 5=111, 6=101).
Free online calculators and tools covering mathematics, unit conversion, text processing, and daily life. Accurate, fast, mobile-friendly, and completely free to use.