Convert Gray Code to Hex
Decode Gray code (reflected binary) to hex, decimal, or binary. Accepts binary or hex-packed input. BigInt-safe, per-line errors. Free, offline, 100% client-side.
- Runs in your browser
- Nothing uploaded
- Free, no sign-up
Decode reflected binary (Gray code) to hexadecimal, decimal, or standard binary. Accepts Gray as bits (1011) or as hex-packed bits (0xA = 1010). BigInt math for any width - 4, 64, 128, or 256 bits.
How to Use Convert Gray Code to Hex
- Paste your Gray code values, one per line. You can include a
0b/0xprefix, spaces, or underscores (1011_0110orDE_AD) - they all get stripped before decoding. - Pick the input mode: "Binary bits" (default) if each line is already in
0/1form, or "Hex-packed Gray" if your Gray code is stored as compact hex (e.g.0xArepresenting Gray bits1010). - Choose the output format: hex (default), decimal, the decoded binary bits, or all four columns tab-separated for pasting into a spreadsheet.
- Toggle UPPERCASE hex if your downstream system expects
0xAFover0xaf. - Press Convert (or Ctrl+Enter / Cmd+Enter). Auto-convert also fires 200 ms after each keystroke so the output updates as you type.
- Read the stats line: lines total, converted, errors, largest bit width, and the largest decimal decoded. Inspect the breakdown below to see each row's Gray → Binary → Decimal → Hex chain.
- Handle errors per line: a bad character shows a red row naming the position (e.g. "Line 3: invalid binary character '2' at position 2") while every other row still decodes.
- Copy or download. Copy uses the Clipboard API with an
execCommandfallback for older browsers; Download saves a plain.txt.
Frequently Asked Questions
How is Gray code decoded into a number?
In two logical stages. Stage one: Gray → standard binary. The MSB passes through unchanged; every subsequent bit is the XOR of the previous output bit and the current Gray bit. Stage two: read that binary as an unsigned integer and format it however you want (hex, decimal, or keep it as binary). Gray 1011 → binary 1101 → hex 0xd (decimal 13).
Why do you make me choose between binary and hex input?
Because auto-detection is ambiguous. The string 1011 is a valid binary Gray code (4 bits, value 13 after decoding) AND a valid hex number (4113 decimal). Guessing based on length or characters would silently give wrong answers on ambiguous inputs. Picking explicitly means the tool always does what you expect.
What does “hex-packed Gray” mean?
It’s when you’ve compressed each nibble of Gray code bits into a hex digit for storage. 0xA represents the 4 Gray bits 1010; 0xDE represents the 8 bits 11011110. Set input mode to “Hex-packed Gray” and the tool unpacks the bits first, then runs the XOR decoder.
Does this handle Gray codes larger than 2^53?
Yes. The decoder uses JavaScript’s native BigInt, so a 256-bit or 1,024-bit Gray code decodes to its exact decimal and hex – no precision loss at 2^53 like you’d get with regular Number. The bit-parallel algorithm (binary ^= binary >> mask) scales linearly in the number of set bits.
Is my data kept private?
Yes. All processing happens in your browser’s JavaScript runtime – no bytes leave your machine. You can confirm this in the Network tab of DevTools: no requests fire during conversion. The tool also keeps working after you disconnect from the internet.
What happens if one line in my batch is invalid?
Only that line fails. The tool processes lines independently, so a stray character becomes one red row (“Line 3: invalid binary character ‘2’ at position 2”) while every other line still decodes. The stats line tells you exactly how many succeeded versus failed.
Does it work for rotary encoder readings?
Yes – that’s one of the main use cases. Absolute rotary encoders and shaft-position sensors emit Gray code because only one bit flips between adjacent positions, preventing transient glitches during transitions. Paste the raw encoder bits or its hex-packed form here to recover the integer position in hex.
Why hex output versus decimal?
Hex is four times more compact than binary (each hex digit is 4 bits) and aligns naturally with byte boundaries. It’s the standard format for logging microcontroller registers, debugging encoder firmware, and embedding values in C/Rust/JS source (0xAF style). If you want a human number instead, switch the output to “Decimal”.
What does the UPPERCASE toggle do?
It controls the case of alphabetic hex digits only. Uppercase on produces 0xAF, off produces 0xaf. The 0x prefix is always lowercase. The toggle is cosmetic – the underlying value is identical either way.
How do I go the other direction (hex back to Gray)?
Use a hex-to-Gray-code converter. The round trip is lossless: each Gray code maps to exactly one decoded value, and each decoded value re-encodes to exactly one Gray code. The encoder formula is gray = binary XOR (binary >> 1) – the inverse of what this tool applies.
Related Tools
Convert Hex to Gray Code →
Convert hex to Gray code (reflected binary) with BigInt precision. Handles 32+ bit values…
Add Hex Numbers →
Add Hex Numbers instantly. Free, offline, client-side tool that outputs results in both hex…
ASCII to Hex Converter →
Convert ASCII to Hex - code points or UTF-8 bytes, space/comma/0x-prefixed, uppercase or lowercase.…
Base32 to Hex Converter →
Base32 to Hex Converter - pick separator, case, and prefix. Free, client-side, instant, offline,…
Base58 to Hex Converter →
Decode Bitcoin, Ripple, or Flickr Base58 strings to hex - with separator, case, and…
Base64 to Hex Decoder →
Decode Base64 to hex bytes - URL-safe variant, separator options, uppercase toggle, UTF-8 aware.…
BCD to Hex Converter →
Convert packed BCD to hexadecimal - decimal-value or nibble mode, BigInt precision, COMP-3 sign.…
Convert Decimal to Hex →
Convert decimal numbers to hexadecimal instantly, individually or in bulk. Free, client-side converter with…
Convert Hex to ASCII →
Decode hexadecimal bytes to ASCII text. Auto-detect separators, handle non-printable bytes four ways, batch…
Convert Hex to BCD →
Convert hex to Binary Coded Decimal - packed, unpacked, or COMP-3 with sign nibble.…
Convert Hex to Binary →
Convert hex to binary with nibble-accurate bit widths. 5 grouping modes, 0b prefix toggle,…
Convert Hex to Decimal →
Convert hex to decimal with BigInt precision. Explicit bit-width two's complement for signed values,…