Skip to content
100% local

Gray code converter

Convert numbers to Gray (reflected binary) code and back, or generate a full Gray code table.

Input
Output

Gray code converter

Gray code — also called reflected binary code — is a way of ordering binary numbers so that only one bit changes between any two consecutive values. This tool converts a number to its Gray code equivalent and back, and pastes straight from whatever format you already have it in.

Choose the input format (decimal, binary or hexadecimal) and the output format independently, then pick a bit width from 4 to 32 bits — the result is zero-padded to that width so every value lines up. Set the direction to "Number → Gray code" to encode, or flip it to "Gray code → number" to decode; the swap button carries the current output back into the input so you can check a round trip in one click. Paste a whole list and each line converts on its own, so batch conversion needs no extra setup.

Turn on "Generate full Gray code table" to list every value for the chosen bit width instead — decimal, binary and Gray columns side by side, either as an aligned table or as CSV you can drop straight into a spreadsheet. Because the row count doubles with every extra bit, table generation is capped at 16 bits; wider widths still work for ordinary conversion.

Everything runs locally in your browser — nothing you paste or convert is ever sent anywhere. Copy the result, download it as a .txt file, or send the output back into the input to chain another conversion.

FAQ

What is Gray code used for?
Gray code is common in rotary encoders, Karnaugh maps and error-correction circuits, because only one bit flips between adjacent values, which avoids ambiguous readings during a transition.
How is Gray code different from regular binary?
In regular binary, multiple bits can flip between consecutive numbers (e.g. 3 → 4 is 011 → 100). In Gray code, exactly one bit changes at every step, which is why it is called "reflected" binary.
What does the bit width setting do?
It fixes how many bits the binary and Gray representations are padded to with leading zeros, so every line in a batch lines up at the same width.
Why is the full table limited to 16 bits?
A Gray code table has one row per value, and that count doubles with every extra bit — 2^16 is already 65,536 rows. Wider bit widths stay available for converting individual values, just not for generating the whole table.
Is my data uploaded anywhere?
No. The conversion runs entirely in your browser — nothing you paste is sent to a server.