Text to Hex

Convert text into its underlying hexadecimal byte values.

The letter A gets written five different ways depending on where you are working — and every single one of them is the same underlying hex value, 41, wearing a different syntax.

Why hex is grouped in pairs

A byte is eight bits, and two hex digits cover exactly that range — 00 to FF, 0 to 255, no waste and no overflow. That clean fit is why text is almost always shown in hex as pairs of digits, one pair per byte, rather than in any other grouping.

The letter A, ASCII code 65, is 41 in hex — four sixteens plus one. Convert a whole word and you get a pair for every character: ‘Hi’ becomes 48 69, since H is 72 and i is 105.

The same character, four different syntaxes

ContextHow the letter A (hex 41) is written
HTML entityA or A
CSS content valueAn escape character followed by the digits 0041
JavaScript stringAn escape character, then u, then the digits 0041
URL / percent encoding%41

Escaping is not quite the same as raw hex conversion

Each of those syntaxes is solving the same underlying problem — representing a character your keyboard or file format cannot type directly — but the rules differ. HTML numeric entities can use decimal or hex. URLs always use hex, prefixed with a percent sign. JavaScript and CSS unicode escapes pad to four hex digits regardless of whether the character needs them.

What they all share is the same root number. Once you know a character’s hex value, converting it into any one of these formats is just a matter of wrapping it in the right punctuation for that context.

Converting text to hex

  1. Take the text one character at a time.
  2. Look up each character’s decimal code.
  3. Convert that decimal value to two hex digits, using A through F for 10 through 15.
  4. Write the hex pairs in order, usually separated by spaces for readability.

Text to hex questions

Why is hex the standard way to represent raw text bytes?

Because two hex digits map exactly onto one byte, with no wasted digits and no overflow. That clean alignment is why hex dumps, colour codes and byte-level debugging all default to it.

Is text-to-hex the same as URL encoding?

Related but not identical. URL encoding percent-encodes specific reserved characters using hex, while a general text-to-hex conversion turns every character into its hex byte value regardless of whether it needs escaping.

Why do some hex representations use four digits per character instead of two?

Because they are representing a Unicode code point rather than a single byte. JavaScript and CSS unicode escapes commonly pad to four hex digits to cover the full Basic Multilingual Plane in one fixed-width block.

Does text-to-hex handle accented letters and emoji?

Yes, provided the tool knows the source encoding, typically UTF-8. Those characters convert to two, three or four hex byte pairs instead of the single pair a plain ASCII character uses.

Can I convert the hex output back into text?

Yes. Splitting the hex string back into pairs, converting each pair to its decimal value, and looking up the corresponding character reverses the process exactly.

Cookie
We care about your data and would love to use cookies to improve your experience.