ASCII to Hex Converter
ASCII to hex converter: enter ASCII text and get one hex byte per character, so ASCII becomes 41 53 43 49 49. Characters outside ASCII are flagged. Pick plain, spaced, 0x or \x output. Conversion happens in your browser.
Use ASCII to Hex for ASCII character codes; use Text to Hex for Unicode characters.
Hex dump, xxd style (5 bytes)
00000000: 4153 4349 49 ASCII
ASCII to hex: look up each character's code
ASCII gives every character a number from 0 to 127, and hex is the number written in base 16. To convert ASCII to hex, take each character in turn, find its code and write that code as two hex digits. The word ASCII is five characters and five bytes, so the result is ten digits.
| Character | Decimal | Hex | Binary |
|---|---|---|---|
| A | 65 | 41 | 01000001 |
| S | 83 | 53 | 01010011 |
| C | 67 | 43 | 01000011 |
| I | 73 | 49 | 01001001 |
| I | 73 | 49 | 01001001 |
Read down the Hex column and the result is 41 53 43 49 49. The second I has the same code as the first because the table is a function of the character alone; position in the text does not matter. Every ASCII character fits in one byte, so the output length is always exactly twice the input length.
Working out the hex by hand
There are two routes when no table is at hand. From the decimal code, divide by 16: the quotient is the first hex digit and the remainder is the second. The letter z is 122, and 122 = 7 × 16 + 10, so the digits are 7 and A, giving 7A. From the binary form, split the eight bits into two groups of four and read each group as a hex digit, as in the diagram: H is 0100 1000, which is 4 and 8, so 48.
With a little practice the anchors do the work without arithmetic. If a letter is in the capitals, its hex is 40 plus its place in the alphabet (A is 1, so 41; Z is 26 = 1A, so 5A). In lower case it is 60 plus the place, so z is 60 + 1A = 7A. For digits it is 30 plus the digit. The only characters that need a lookup are punctuation, and they are few: the space is 20, the full stop 2E, the comma 2C, the hyphen 2D and the slash 2F.
Hex values by kind of character
The 95 printable characters sit in four groups, and the first hex digit tells you which one. The lists below give every character in a group with its hex code, ready to read across. The space comes first at 20; the unprintable codes (00 to 1F and 7F) are on the ASCII table.
| Group | Hex range | Characters and codes |
|---|---|---|
| Digits | 30 to 39 | 0=30 1=31 2=32 3=33 4=34 5=35 6=36 7=37 8=38 9=39 |
| Capital letters | 41 to 5A | A=41 B=42 C=43 D=44 E=45 F=46 G=47 H=48 I=49 J=4A K=4B L=4C M=4D N=4E O=4F P=50 Q=51 R=52 S=53 T=54 U=55 V=56 W=57 X=58 Y=59 Z=5A |
| Lower case letters | 61 to 7A | a=61 b=62 c=63 d=64 e=65 f=66 g=67 h=68 i=69 j=6A k=6B l=6C m=6D n=6E o=6F p=70 q=71 r=72 s=73 t=74 u=75 v=76 w=77 x=78 y=79 z=7A |
| Punctuation, 21 to 2F | 21 to 2F | !=21 "=22 #=23 $=24 %=25 &=26 '=27 (=28 )=29 *=2A +=2B ,=2C -=2D .=2E /=2F |
| Punctuation, 3A to 40 | 3A to 40 | :=3A ;=3B <=3C ==3D >=3E ?=3F @=40 |
| Punctuation, 5B to 60 | 5B to 60 | [=5B \=5C ]=5D ^=5E _=5F `=60 |
| Punctuation, 7B to 7E | 7B to 7E | {=7B |=7C }=7D ~=7E |
Most of the work is memorizing three anchors: 30 for zero, 41 for A and 61 for a. Count forward from the anchor to reach the rest of a run. The letter M is the 13th letter, so it is 41 + 0C = 4D. The digit 7 is 30 + 7 = 37. The letter n is 61 + 0D = 6E.
ascii2hex output formats
The converter writes the same bytes in whichever notation the next step needs. Fixed-width hex without separators is common in protocols and databases. Spaced upper case is what debuggers print. The 0x and \x prefixes paste directly into C, C++, Python and JavaScript source.
| Notation | Output |
|---|---|
| Plain, lower case | 4153434949 |
| Plain, upper case | 4153434949 |
| Spaced | 41 53 43 49 49 |
| Colons | 41:53:43:49:49 |
| 0x prefix (C array body) | 0x41, 0x53, 0x43, 0x49, 0x49 |
| \x escapes (string literal) | \x41\x53\x43\x49\x49 |
Letter case is only a matter of style, but stay consistent inside one file: some parsers accept 0x and not 0X, and plain string comparison treats 4a and 4A as different values.
Line breaks: 0A, 0D and the trailing newline
A line break is a character like any other, and ASCII has two for it. Line feed (0A) ends a line on Unix, Linux and macOS. Carriage return and line feed (0D 0A) end a line on Windows and in network text protocols. Two lines typed in the input box come out as 6F 6E 65 0A 74 77 6F when the break is a line feed alone, and as 6F 6E 65 0D 0A 74 77 6F when it is the Windows pair.
A trailing break at the very end of the input adds a final 0A that is easy to miss on screen. When a hex string is compared with a value from another system and differs by exactly one byte at the end, the break is the first thing to check. Files created by many editors end with a final line feed by convention, while text pasted into a form often does not.
The same character in decimal, binary, octal and hex
Documentation uses all four bases for ASCII codes, and old Unix manuals favor octal. Converting between them is arithmetic on the same number. Hex is the compact one, because two hex digits cover a byte exactly: the first digit is the upper four bits and the second the lower four.
| Character | Decimal | Hex | Octal | Binary |
|---|---|---|---|---|
| A | 65 | 41 | 101 | 01000001 |
| a | 97 | 61 | 141 | 01100001 |
| 0 | 48 | 30 | 060 | 00110000 |
| space | 32 | 20 | 040 | 00100000 |
| ~ | 126 | 7E | 176 | 01111110 |
Binary shows why the layout works. Every printable ASCII byte starts with 0 (it is 7-bit), and the upper-case letter A and the lower-case a differ only in the third bit from the left. Reading the high four bits as a hex digit gives the first digit of the code, which is why 4 and 5 mean capitals and 6 and 7 mean lower case.
Hex prefixes that give away the format of text data
Text formats begin with characters that are easy to spot once you know their hex. A JSON object starts with 7B (the opening brace), usually followed by 22 (a quotation mark), so 7B 22 is the beginning of a key. An XML declaration begins 3C 3F 78 6D 6C, which is the five characters <?xml. An HTML document that opens with a doctype starts 3C 21 44 4F 43 54 59 50 45, the nine characters <!DOCTYPE. A byte order mark in front of any of these (EF BB BF) means the first three bytes are not part of the text.
Knowing these makes a raw dump readable at a glance. If a capture begins 3C 68 74 6D 6C 3E, it is the tag <html>; if it begins 7B 0A 20 20, it is a pretty-printed JSON object with a line feed and two spaces of indentation. The line-feed byte 0A in the third position is the clue that the file was formatted by a program and not minified.
ASCII hex in protocols and file formats
Hex is the usual way to write ASCII bytes when a protocol carries binary-safe text. The NMEA 0183 sentences sent by GPS receivers end in a checksum that is the XOR of every character between the $ and the * sign, written as two hex digits. For the sentence GPGLL,4916.45,N,12311.12,W,225444,A, the characters XOR to 1D, so the line ends *1D. The checksum is itself ASCII hex: the bytes sent are 31 44, the characters 1 and D.
Intel HEX files, used to load firmware into microcontrollers, are ASCII text from start to finish. Each line begins with a colon and writes the record in hex digits, so the bytes on disk are the hex digits' own ASCII codes (the digit 4 stored as 34, the letter F as 46). The format therefore doubles the size of the data and then writes each digit as a byte. Similar conventions appear in SMTP, HTTP chunk sizes (which are hex numbers written in ASCII), and MIME quoted-printable text.
What happens to characters outside ASCII
ASCII has no code for é, ñ, €, or any character from a non-Latin script. A letter such as é has several possible byte forms depending on the encoding (E9 in Latin-1, C3 A9 in UTF-8), so there is no single correct ASCII hex for it. The converter does not pick one: it marks the character, states its Unicode value and its position, writes 3F in its place so the output length matches the input, and tells you to use a wider encoding.
For text that includes such characters, text to hex converts with UTF-8, UTF-16 or Latin-1. To check that a hex string contains only ASCII, run it through hex to ASCII: any byte above 7F is reported. The definition of the 7-bit code is in RFC 20.
ASCII to hex in Python, JavaScript, C and the shell
"ASCII".encode("ascii").hex() # '4153434949'
[format(ord(c), "02X") for c in "ASCII"] # ['41', '53', '43', '49', '49'][..."ASCII"].map(c => c.charCodeAt(0).toString(16).padStart(2, "0")).join(" ") // '41 53 43 49 49'const char *s = "ASCII";
for (const char *p = s; *p; p++) printf("%02X ", (unsigned char)*p); /* 41 53 43 49 49 */printf 'ASCII' | xxd -p # 4153434949
printf 'ASCII' | od -An -tx1 # 41 53 43 49 49
[int[]][char[]]"ASCII" | ForEach-Object { $_.ToString("X2") } # 41 53 43 49 49The cast to unsigned char in the C line matters: on platforms where char is signed, a byte above 7F would otherwise print as FFFFFF followed by two digits.
Questions about converting ASCII to hex
What is the hex code for the letter A?
41. Capital A is ASCII 65, and 65 in hexadecimal is 4 × 16 + 1 = 41. Lower case a is 61, and the digit character 0 is 30.
What is the difference between ascii2hex and text to hex?
ASCII to hex is the 128-character case: each character is exactly one byte and the table has 128 rows. Text to hex covers everything Unicode can write, where a character may need up to four bytes. For ASCII-only input the two give the same output.
Why does a space become 20?
The space is a printable character with code 32 in decimal, and 32 is 20 in hex (2 × 16). It is the first printable ASCII character, which is why punctuation and digits follow it at 21 and above.
Can I get the hex without spaces?
Yes. Choose no separator and the output is one continuous string. Spaces, commas, colons and the 0x, \x and % prefixes are all options, and the byte values are the same in each.
What does the converter do with é or €?
They are not ASCII. The converter flags each one with its position and writes 3F, a question mark, in its place. Use the text to hex converter with UTF-8 when the input contains such characters.
