W3docs

String Functions

Hex to Text Decoder

Decode a hex-encoded string (e.g. `48656c6c6f`) back to its UTF-8 text representation.

About the hex to text decoder

This tool decodes a hex-encoded string back into readable text. Feed it a run of hexadecimal digits — for example 48656c6c6f — and it reads them two characters at a time, converts each pair into the byte it represents, and reassembles the original text (Hello, in that example). It's the inverse of hex-encoding text into a 48656c6c6f-style string, which is what a tool like the Binary to Hex Converter produces.

Everything runs client-side in the browser; nothing you paste is sent to a server. The transform trims leading and trailing whitespace, checks that what's left has an even number of characters and consists only of 0-9, a-f, and A-F, then converts each two-character pair into a byte with parseInt(pair, 16). The resulting bytes are decoded as UTF-8 with the browser's built-in TextDecoder, so multi-byte characters — accented letters, emoji — reconstruct correctly instead of turning into mangled output.

You'll reach for this when inspecting a hex dump from a debugger or packet capture, decoding a value a database or log stored as hex, or checking the output of PHP's hex2bin(), whose behavior this tool mirrors (this JS port throws on invalid input instead of returning false). It's also useful for verifying a bin2hex() round-trip, or just reading what a hex string actually spells out without writing a throwaway script.

Examples

Decode a hex string to texttext
Input:   48656c6c6f
Output:  Hello

Each two-digit hex pair decodes to one byte: 48→H, 65→e, 6c→l, 6c→l, 6f→o.

Multi-byte UTF-8 characterstext
Input:   636166c3a9
Output:  café

é is two bytes in UTF-8 (c3 a9), so it takes four hex digits — the decoder reads bytes, not one hex pair per visible character.

The same operation in PHPphp
$hex = "48656c6c6f";
echo hex2bin($hex); // "Hello"

var_dump(hex2bin("xyz")); // bool(false) — odd-length input

This tool is a JS port of PHP's hex2bin() — same byte-pairing logic — but it throws a JS Error on invalid input instead of returning false.

Frequently asked questions

What does hex2bin do?

hex2bin() is a PHP function that converts a string of hexadecimal digits back into the raw bytes it represents — the reverse of bin2hex(). This tool runs the same logic in the browser: paste in 48656c6c6f and you get Hello back, decoded as UTF-8 text.

Why am I getting an 'Invalid hex input' error?

The decoder requires the input, after trimming outer whitespace, to have an even number of characters and contain only 0-9, a-f, or A-F. An odd-length string or any character outside that set throws this error instead of producing a wrong result.

Can I decode hex with spaces between the bytes, like 48 65 6c?

Not directly — only leading and trailing whitespace is trimmed, so spaces between byte pairs trigger the 'Invalid hex input' error. Strip the internal spaces first (input.replace(/\s+/g, '') in JavaScript) so you're left with one continuous run of hex digits.

Is this the same as converting hex to binary digits (0s and 1s)?

No. Despite the URL's legacy 'bin' naming, this tool decodes hex into UTF-8 text — PHP's hex2bin() behavior — not into a string of 0/1 bits. For bit-level binary output, use the String to Binary Converter instead.

Does this tool send my input to a server?

No. Decoding happens entirely in your browser using JavaScript's built-in TextDecoder; nothing you paste is transmitted, logged, or stored.