Binary to Gray Code Converter – Online Free Tool
Convert binary to Gray code (BRGC) - XOR algorithm, bit-width preserved, step-by-step display, BigInt. Free, client-side, instant, offline, secure.
Transform binary numbers into their Binary Reflected Gray Code (BRGC) equivalent. Uses the canonical XOR formula g = b ^ (b >> 1). Preserves bit width, verifies the single-bit-change property on consecutive inputs, handles arbitrary widths via BigInt.
How to Use Binary to Gray Code Converter – Online Free Tool
- Paste binary values, one per line. All 0s and 1s. Leading zeros matter - they define the bit width.
0011is 4-bit;11is 2-bit. The output preserves your input width. - Pick an output format.
Plainshows just the Gray code.Compareshowsbinary → grayside by side (handy for verifying by eye).Bit groupsinserts a space every 4 bits on the output, helpful for long bit widths. - Enable “Show XOR steps” for a per-bit breakdown of the first valid line. Each bit
g[i] = b[i] XOR b[i-1](exceptg[0] = b[0]) is listed so you can verify the algorithm by hand. - Watch for the Gray-code property confirmation. If you enter sequential binary values (
0000,0001,0010,0011...), the stats line should say✓ sequential Δ=1 (true Gray code)- each output differs from the previous by exactly one bit, which is Gray code’s defining property. - Check the stats. Total lines · total input bits · validity · delta range (if applicable). Invalid lines show inline
ERROR:with the bad char and its position. - Copy or download. Output goes to clipboard or saves as
gray-code-<timestamp>.txt.Ctrl+Enter/Cmd+Enterruns convert + copy. - Cross-check by reversing. Feed Gray codes into our Gray-code-to-binary tool (sibling page) to verify the round-trip preserves your original values.
Frequently Asked Questions
What is Gray code?
Gray code is a binary numeral system where two consecutive values differ by only one bit. It is used in rotary encoders, error correction, and digital communications to prevent glitches during transitions.
How does the XOR algorithm work?
Gray code is produced by XORing each bit with its more-significant neighbor. The most-significant bit stays the same, and each subsequent bit is original XOR previous-original.
Why preserve bit width?
Gray code operations often rely on fixed-width values (e.g., 8-bit rotary encoders). The tool pads the input with leading zeros to preserve your chosen width so the output is directly usable.
Does it show the algorithm step by step?
Yes. Step-by-step mode displays each XOR operation with both input bits and the resulting Gray code bit, making it useful for students and for verifying hand calculations.
Where is Gray code used in real systems?
Rotary encoders, Karnaugh maps, digital communication error detection, analog-to-digital converters, and some hardware state machines.
Is my data secure?
Yes. Conversion runs entirely in your browser. Nothing is uploaded or logged.
Is this tool free?
Yes, completely free with no account needed.
What if my input has invalid characters?
The tool checks the input and reports any non-binary characters so you can correct them before converting.
Can I reverse the conversion?
Yes. A complementary Gray code to binary tool is available for the inverse operation.
How large can my binary input be?
The tool supports inputs up to thousands of bits using JavaScript BigInt, so practical lengths (32-bit, 64-bit, or larger) work without precision loss.