IP331.com | Online Tools
HomeBase ConverterArbitrary Radix Gray Code Converter

Arbitrary Radix Gray Code Converter

Convert between binary and Gray code, plus explore arbitrary radix Gray codes with step-by-step derivation

Binary Number

Gray Code Conversion Principle

① Binary → Gray: MSB same, Gᵢ = Bᵢ XOR Bᵢ₋₁
② Gray → Binary: MSB same, Bᵢ = Gᵢ XOR Bᵢ₋₁
③ Successive values differ by only one bit

Gray code (reflected binary) ensures only one bit changes between consecutive numbers, minimizing transition errors.

Gray code is not a positional number system. The same sequence of bits represents different values depending on its position in the sequence.

What Is Gray Code?

Gray code, or reflected binary code, is a binary numeral system where consecutive values differ by exactly one bit, invented by Frank Gray in 1953.

Single Bit Change

000 → 001 → 011 → 010 → 110 → 111 → 101 → 100. Only one bit flips at each step.

Error Minimization

In mechanical encoders, single bit changes prevent large errors if a sensor misreads a transition.

Binary → Gray

G₀ = B₀, G₁ = B₁^B₀, G₂ = B₂^B₁, G₃ = B₃^B₂, etc. (^ = XOR)

Gray → Binary

B₀ = G₀, B₁ = G₁^B₀, B₂ = G₂^B₁, B₃ = G₃^B₂, etc. (^ = XOR)

💡 Teaching Example: Binary 1010 → Gray: 1 (same), 1^0=1, 0^1=1, 0^0=0 → 1110. Gray 1110 → Binary: 1, 1^1=0, 1^0=1, 0^1=1 → 1010.

Applications

Rotary Encoders Position Sensors Karnaugh Maps Error Correction Digital Logic

Frequently Asked Questions

What is Gray code?
Gray code, also known as reflected binary code, is a binary numeral system where two successive values differ in only one bit. This minimizes errors during state transitions.
How do you convert binary to Gray code?
The most significant bit (MSB) stays the same. Each subsequent bit is the XOR of the current binary bit and the previous binary bit. Formula: Gᵢ = Bᵢ XOR Bᵢ₋₁
How do you convert Gray code to binary?
The MSB stays the same. Each subsequent bit is the XOR of the current Gray bit and the previous binary bit. Formula: Bᵢ = Gᵢ XOR Bᵢ₋₁
What is Gray code used for?
Gray code is used in rotary encoders, digital communications, error correction, Karnaugh maps, position sensors, and anywhere minimal state change is important.

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