IP331.com | Online Tools
HomeBase ConverterBinary to Gray Code Converter

Binary to Gray Code Converter

Convert standard binary to Gray code (reflected binary) with step-by-bit XOR operations

Input Binary

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.

💡 Teaching Example: Convert binary 0101 to Gray. Step 1: Gray₀ = 0. Step 2: Gray₁ = 1 XOR 0 = 1. Step 3: Gray₂ = 0 XOR 1 = 1. Step 4: Gray₃ = 1 XOR 0 = 1. Result: 0111. Verify: 4=0110, 5=0111, 6=0101 - only one bit changes between them!

Applications

Rotary Encoders Position Sensors Digital Communications Error Correction Karnaugh Maps

Frequently Asked Questions

How do you convert binary to Gray code?
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).

More Base Converter Tools

Free online calculators and tools covering mathematics, unit conversion, text processing, and daily life. Accurate, fast, mobile-friendly, and completely free to use.

© 2026 IP331.com — Free Online Tools. All rights reserved.

About · Contact · Privacy Policy · Cookie Policy · Terms of Use · Disclaimer · Sitemap