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.
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
- Enter your input in the tool above.
- Adjust any options to your preference.
- Use the Copy or Download buttons to save the result.
- 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.
Related tools
.bashrc / .zshrc Alias & Config Manager
Build shell aliases, functions, exports, and PATH edits in a visual editor, then export a clean, commented .aliases file sourced from both .bashrc and .zshrc — with shadowing detection against shell builtins and common CLI tools, function suggestions when args are needed, starter packs (git, docker, kubectl, navigation, safety, ls, dev, devops, data science), import of existing rc files, dedupe, history (localStorage), and shareable URL. 100% client-side.
Add / Subtract Date Calculator
Add or subtract years, months, weeks, days, hours, minutes and seconds from a starting date/time. Calendar-day or business-day mode with custom weekend + holiday list. Month-end policy toggle (clamp to last day vs overflow). Repeat/series mode (e.g. every 2 weeks x 10) with CSV export. Shareable URL. 100% client-side.
Age Calculator
Calculate exact age from a birth date in calendar years/months/days (no negative-day bugs) plus totals in months/weeks/days/hours/minutes/seconds. Next-birthday countdown with weekday. Feb-29 birthday policy toggle. Milestones (1,000 days, 10,000 days, 1 billion seconds). Zodiac sign + Chinese zodiac. Age gap comparison. Shareable URL. 100% client-side.