Binary to Gray Code Converter

Convert between binary and Gray code with step-by-step process and reference table.

🔧
Capacitor Code Calculator

Decode resistor-style capacitor markings? Try our Capacitor Code Calculator.

Calculate →

Input

Result

Gray Code

Step-by-Step Process

4-Bit Reference Table

Decimal Binary Gray Code
000000000
100010001
200100011
300110010
401000110
501010111
601100101
701110100
810001100
910011101
1010101111
1110111110
1211001010
1311011011
1411101001
1511111000

Understanding Gray Code

Gray code (also known as reflected binary code) is a binary numeral system where two successive values differ in only one bit. Unlike standard binary, where multiple bits can change simultaneously between consecutive numbers, Gray code minimizes bit transitions. This property makes it invaluable in digital communication, rotary encoders, and error reduction in analog-to-digital converters.

Conversion Formulas

Binary to Gray: G[i] = B[i] XOR B[i-1], G[MSB] = B[MSB]
Gray to Binary: B[i] = G[i] XOR B[i-1], B[MSB] = G[MSB]

For Binary to Gray conversion, the most significant bit (MSB) stays the same. Each subsequent Gray bit is the XOR of the current binary bit and the binary bit to its left. For Gray to Binary, the MSB also stays the same, but each subsequent binary bit requires XORing the current Gray bit with the already-computed binary bit to its left — a sequential accumulation process.

How to Convert Binary and Gray Code

1
Select conversion direction: Binary → Gray or Gray → Binary.
2
Choose bit width (4-bit, 8-bit, or custom).
3
Enter the binary or Gray code value.
4
View the converted result and step-by-step XOR process.
5
Check the reference table for common 4-bit conversions.

Frequently Asked Questions

What is Gray code?

Gray code (aka reflected binary code) is a binary numeral system where two successive values differ in only one bit. It reduces errors in digital communication and positioning systems.

How do I convert binary to Gray code?

Keep the MSB the same. For each subsequent bit, XOR the current binary bit with the binary bit to its left. G[i] = B[i] XOR B[i-1].

How do I convert Gray code to binary?

Keep the MSB the same. For each subsequent bit, XOR the current Gray bit with the already-computed binary bit to its left. B[i] = G[i] XOR B[i-1]. This is a sequential accumulation process.

What is Gray code used for?

Gray code is used in Karnaugh maps for logic minimization, rotary encoders to prevent glitch states, digital communication to minimize bit errors, and analog-to-digital converters for smoother transitions.

What is the Gray code for decimal 5?

Decimal 5 = binary 0101. Converting: G[3]=0, G[2]=1⊕0=1, G[1]=0⊕1=1, G[0]=1⊕0=1. Gray code = 0111.