How do you convert ASCII to hex?
Take each character's ASCII code and write it in base 16. H is 72 in decimal, which is 48 in hex, because 4 × 16 + 8 = 72. This converter does that for every character in your text and prints the bytes as lowercase two-digit pairs separated by spaces, so Hi! becomes 48 69 21.
Hex is the usual way to show raw bytes because two hex digits cover exactly one byte (00 to ff), and the ASCII range fits inside 00 to 7f.
Using the converter
- Type or paste the text.
- Click Convert.
- Copy the hex. Every byte is two digits, so a tab comes out as
09, not9.
Example: GET / converts to 47 45 54 20 2f. If you've ever looked at an HTTP request in a packet capture, those are the first bytes you'll see on the wire, and recognising 47 45 54 20 as "GET " is a handy debugging reflex.
Reading ASCII hex without a chart
The ASCII layout is cleaner in hex than in decimal, because character groups start on round numbers:
| Hex range | Characters | Pattern |
|---|---|---|
00 to 1f |
Control codes | 09 tab, 0a line feed, 0d carriage return |
20 |
Space | |
30 to 39 |
Digits 0 to 9 | Second digit equals the digit: 37 is 7 |
41 to 5a |
A to Z | 41 is A |
61 to 7a |
a to z | Lowercase = uppercase + 20 |
7f |
DEL | Last ASCII code |
Two tricks fall out of this. A digit character is 3 followed by the digit itself, so 2026 is 32 30 32 36. And uppercase and lowercase letters differ only in the 20 bit: 41 is A, 61 is a. Converting AZaz gives 41 5a 61 7a, which shows both ends of each alphabet. The ASCII table has the complete list if you need a symbol.
Turning the output into code
Space-separated pairs are easy to read, but code usually wants a specific notation. These are the common ones for the bytes of Hi:
| Where | Notation | How to get it from the output |
|---|---|---|
| C, Python, JavaScript strings | "\x48\x69" |
Replace each space with \x and add \x at the start |
| C or Java byte array | {0x48, 0x69} |
Replace each space with , 0x and add 0x at the start |
Python bytes.fromhex() |
bytes.fromhex('48 69') |
Paste as-is, spaces are allowed |
| URL percent-encoding | %48%69 |
Replace each space with % and add % at the start |
| HTML numeric reference | Hi |
Wrap each byte in &#x and ; |
The find and replace tool handles these rewrites in one step. Python's bytes.fromhex accepts whitespace between pairs, so this page's output works there without changes. For URLs, note that you'd normally percent-encode only reserved characters, not letters; RFC 3986 lists which ones, and the URL encoder applies those rules for you. The HTML form works byte for byte only with ASCII; for other characters HTML references the code point (é is é), not the UTF-8 bytes.
Past the ASCII range
Strict ASCII stops at 7f. When your text contains anything beyond that, the converter switches to UTF-8 bytes rather than failing, following RFC 3629. é becomes c3 a9 and € becomes e2 82 ac. Two consequences:
- The byte count no longer equals the character count.
caféis four characters but five bytes. - Any byte from
80toffin the output tells you the input had a non-ASCII character in it.
If multi-byte encoding is the thing you're actually investigating, the text to hex guide covers it in depth. For pure ASCII input, every character gives exactly one pair, so you can line the output up against the input one-to-one.
Checking your result
Paste the hex into hex to ASCII and you should get your original text back exactly. If you edited the pairs by hand, that round trip is the quickest way to catch a typo, since a single wrong digit changes a character and a missing digit makes the pair count odd, which the decoder rejects.
Last updated