UnQTools
Developer Runs in your browser

Gray Code Converter (Binary ↔ Gray, Sequence, N-ary, Balanced)

Convert between binary/decimal and reflected Gray code in both directions with XOR-step working, generate n-bit Gray-code sequences (0…2ⁿ−1) with the single-bit-change property highlighted, build n-ary and balanced Gray codes, and view the full truth table. BigInt support for wide values. 100% client-side & offline.

100% Private Works Offline Instant

About Gray Code Converter (Binary ↔ Gray, Sequence, N-ary, Balanced)

Convert between binary/decimal and reflected Gray code in both directions with XOR-step working, generate n-bit Gray-code sequences (0…2ⁿ−1) with the single-bit-change property highlighted, build n-ary and balanced Gray codes, and view the full truth table. BigInt support for wide values. 100% client-side & offline. Everything runs locally in your browser — your data never leaves your device.

How to use

  1. Enter your input in the tool above.
  2. Adjust any options to your preference.
  3. Use the Copy or Download buttons to save the result.
  4. Everything happens locally — your data never leaves your browser.

FAQ

How does binary-to-Gray conversion work?

Gray code (also called reflected binary) is generated from a normal binary number by XORing each bit with the bit to its left: gᵢ = bᵢ ⊕ bᵢ₊₁. The most-significant bit is copied unchanged. The result is a code where successive values differ by exactly one bit, which is why Gray code is used in rotary encoders, Karnaugh maps, and error-reduction schemes.

How does Gray-to-binary conversion reverse it?

To recover the binary value, you do a prefix-XOR: starting from the MSB (which is copied), each binary bit bᵢ = gᵢ ⊕ bᵢ₊₁ — that is, XOR the Gray bit with the previously-computed binary bit. The tool shows this as a step table so you can follow each XOR. Both directions also support decimal input/output and any bit width with zero-padding.

What is the Gray code sequence generator?

Given n bits, the generator produces all 2ⁿ values from 0 to 2ⁿ−1 in Gray-code order, highlighting the single bit that flips between successive entries. You can verify the single-bit-change property (including the wrap from the last value back to the first), and view a complete truth table mapping index → binary → Gray → changed-bit.

What are n-ary and balanced Gray codes?

N-ary Gray code generalises the binary version to base-r digits — each successive value differs in exactly one digit by ±1, useful for non-binary sensors. Balanced Gray code is a special reflected Gray code where each bit position toggles roughly the same number of times across a full cycle (within ±1 of the average), which is important when each bit flip has a wear or signal cost. The tool generates both.

What extra features does this tool have compared to other Gray code converters?

(1) Binary → Gray with XOR step table. (2) Gray → binary with prefix-XOR step table. (3) Decimal input/output alongside binary. (4) Selectable bit width with zero-padding. (5) n-bit sequence generator (0…2ⁿ−1) with single-bit-change highlight. (6) Wrap-around single-bit-change verification. (7) N-ary Gray code (any base r ≥ 2). (8) Balanced Gray code generator. (9) Truth-table view. (10) BigInt support for wide values (up to 2ⁿ−1 where n ≤ 53 safely, larger via BigInt). (11) History (localStorage, last 20). (12) Shareable URL. 100% client-side and offline — your data never leaves the device.

Search tools and actions

Search across all 616 tools, categories, and quick actions.