Convert Gray Code to Hexadecimal
Decode binary Gray code bits into hexadecimal, decimal, or standard binary. BigInt-safe, per-line errors, UPPERCASE toggle, 0x prefix toggle. Free, offline, client-side.
Decode reflected binary (Gray code) bits into hexadecimal via the MSB-first XOR chain, then a base-16 render. Accepts 0b prefixes, spaces, and underscore separators. BigInt math for any width.
How to Use Convert Gray Code to Hexadecimal
- Paste your Gray code values, one per line. Each line must be binary bits (0s and 1s). Prefix
0band separator characters like spaces or underscores are stripped automatically. - Choose the output format: hex (default), decimal, the decoded binary bits, or all four columns tab-separated for spreadsheet paste.
- Toggle UPPERCASE hex for
0xDEADBEEF-style output when your target system or log convention prefers it. - Toggle the
0xprefix off if your downstream formatter adds its own prefix (some logging libraries or C macros). - 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 and breakdown: stats show total lines, successful vs failed, max bit width, and largest decimal. The breakdown lists each row's Gray → Binary → Decimal → Hex chain.
- Errors are per line: a stray character flags one red row with its exact position while every other line still converts. The batch never aborts.
- Copy or download. Copy uses the Clipboard API with an
execCommandfallback; Download saves a plain.txtfile.
Frequently Asked Questions
How is Gray code decoded to hexadecimal?
In two logical stages. Stage one converts Gray bits to standard binary: the MSB passes through unchanged, then each subsequent bit is the XOR of the previous output bit with the current Gray bit. Stage two reads that binary as an unsigned integer and renders it in base 16. Gray 1011 → binary 1101 → hex 0xd (decimal 13).
Why is this tool binary-input-only?
So the semantics are unambiguous. A string like 1011 is a valid 4-bit binary Gray code AND a valid hex number – there’s no safe way to auto-detect which the user meant. This converter treats input as binary always; if you have Gray values already packed in hex form, use the “Gray code to hex” tool in the Hex category which has an explicit hex-input mode.
Does this support 64-bit and larger Gray codes?
Yes – and far beyond. The decoder uses JavaScript’s native BigInt, so 256-bit or even 1,024-bit Gray codes produce exact decimal and hex output. Ordinary Number arithmetic would silently round off values past 253 − 1; BigInt has no fixed upper bound.
What does the UPPERCASE hex toggle change?
Only the case of alphabetic hex digits. With it on, you get 0xDEADBEEF; off, 0xdeadbeef. The 0x prefix itself is always lowercase when included. The underlying value is identical – it’s purely a display preference matching your logging or codebase conventions.
When would I disable the 0x prefix?
When a downstream formatter will add its own prefix or when you’re pasting into a context that expects bare hex (spreadsheet cell, CSV column, certain C macros like HEX_STR(%02X)). With the prefix off, 0xAF becomes just AF.
What happens if my Gray code isn’t a multiple of 4 bits?
Nothing unusual – the tool still works correctly. The hex output shows the minimum nibbles needed to represent the value, so 5-bit Gray 10110 decodes to binary 11011 (decimal 27, hex 0x1b). There’s no forced zero-padding to align to nibble boundaries – the breakdown preserves the original bit width for reference.
Is this safe for converting sensitive encoder data?
Yes. Every byte of processing happens in your browser’s JavaScript runtime – no bytes are uploaded or logged by any server. Open the Network tab in DevTools to confirm no requests fire during conversion. The tool continues to work even after you disconnect from the internet.
How does this differ from the Hex-category “gray code to hex” tool?
This tool is binary-input-only – each line is always interpreted as raw Gray bits. The Hex-category companion has an additional “hex-packed” input mode where each hex digit represents 4 Gray bits (so 0xA means Gray bits 1010). Use this one for bit-level Gray sources like encoder datasheets; use the companion for pre-packed hex Gray streams.
Can I batch-convert a lookup table at once?
Yes – paste one value per line. The tool processes each independently, so a corrupted line in row 47 becomes one red breakdown row while rows 1-46 and 48-end all convert successfully. The output textarea contains only the successful conversions; the stats row tells you the counts.
How do I go from hex back to Gray code?
Use a hex-to-Gray-code converter. The round trip is lossless because Gray↔binary↔hex is bijective: encode a value to Gray with gray = bin XOR (bin >> 1), decode it back here, and you get the original. Both conversions run in O(n) bit length.