Tools

Home
Binary to Base64Text to ASCIIString to HexBase64 to HexHex to Base64

Binary to Gray Code Converter

Convert binary numbers to Gray code online. Each successive Gray code value differs in only one bit.

Your files never leave your browser
INPUT (BINARY)0 values
OUTPUT (GRAY CODE)0 values
Ready·Binary to Gray Code

Paste binary values one per line and get their Gray code equivalents instantly — handy when you're working with rotary encoders, Karnaugh maps, or any hardware where only one bit should flip between states. Swap mode runs the reverse conversion, and bit padding keeps outputs aligned at 4, 8, 16, or 32 bits. And everything runs in your browser. Nothing gets uploaded.

How to Use

Enter binary numbers in the left panel, one per line. You can type, paste, or click Sample for example values.

Choose bit padding (auto, 4, 8, 16, or 32 bits) and optionally enable Show decimal equivalents to see the decimal value alongside each result.

Click Convert or leave Live mode enabled for real-time conversion as you type.

Copy, Download, or Swap the result. Swap converts Gray code values back to binary.

Frequently Asked Questions

What is Gray code?

Gray code (also called reflected binary code) is a binary numeral system where two successive values differ in only one bit. It was patented by Frank Gray in 1953. Unlike standard binary where incrementing can change multiple bits at once (e.g. 0111 to 1000 flips all four bits), Gray code ensures only a single bit changes between consecutive values. This property makes it extremely useful in reducing errors in digital communications and hardware systems.

How is binary converted to Gray code?

The conversion uses a simple bitwise algorithm: the most significant bit (MSB) of the Gray code is the same as the MSB of the binary number. Each subsequent Gray code bit is the XOR (exclusive OR) of the current binary bit and the previous binary bit. Mathematically, this is expressed as: gray = binary XOR (binary >> 1), where >> is a right bit-shift. For example, binary 1010 becomes Gray code 1111.

What are common uses for Gray code?

Gray code is widely used in rotary encoders and position sensors where only one bit changing at a time prevents reading errors at transition boundaries. It is also used in Karnaugh maps for logic simplification, in error correction for digital communications, in genetic algorithms, and in analog-to-digital converters. The single-bit-change property eliminates glitches that could occur when multiple bits change simultaneously.

Can I convert Gray code back to binary?

Yes. Click the Swap button to switch the output into the input panel, which automatically changes the mode to Gray-code-to-binary. The reverse algorithm works by keeping the MSB the same, then XOR-ing each Gray code bit with the previously computed binary bit to reconstruct the original binary value.

What does the bit padding option do?

Bit padding controls the minimum number of bits displayed in the output. "Auto" uses the natural length of each binary input. Selecting 4, 8, 16, or 32 pads the output with leading zeros to that width. This is useful for consistent formatting, especially when working with fixed-width registers or data buses in hardware design.

Share: