Here is how to convert ASCII text to hex: find the ASCII value of each character, write that value as two hexadecimal digits, and keep the characters in their original order. For example, ID=42 becomes 49 44 3D 34 32.
That small conversion is useful when a device expects a command as bytes, an API requires a hex-encoded field, or you need to inspect invisible characters in a message. A reliable result preserves everything in the source, including spaces, letter case, punctuation, and line endings.
The method you choose depends on the task. Manual lookup works for a short example. A converter handles occasional text, while code is better for repeatable output and strict input checks. Before using any method, confirm that your source really is ASCII and that the receiving system expects the format you plan to produce. The complete ASCII chart below provides the character codes needed for manual lookup.
The Conversion in Four Actions
To convert ASCII to hexadecimal, read each character, look up its numeric ASCII code, convert that code to base 16, and write it with two digits. Join the results in order. ASCII values range from decimal 0 to 127, so every encoded byte falls between hex 00 and 7F.
Check the Input Before Choosing a Tool
ASCII, short for American Standard Code for Information Interchange, defines 128 character codes. These include English letters, decimal digit characters, common punctuation, and control characters such as tabs and line feeds.
ASCII character codes identify the source characters; hexadecimal notation changes how their numeric values are displayed.
The printable ASCII range runs from 20 through 7E in hexadecimal, including space. Values below 20, along with 7F, cover non-printing codes. A message can therefore be valid ASCII even when some of its contents are invisible.
Plain "status" uses ASCII characters. Curly quotation marks around that same word do not. Accented names, emojis, and many currency symbols also require another character encoding.
Avoid treating “extended ASCII” as one universal format. Different eight-bit encodings assign different meanings to values above 127. If an application requires strict ASCII, rejecting unsupported input is safer than silently deleting or replacing it.
For ASCII-only text, UTF-8 produces the same byte values. That compatibility is useful, but a tool that accepts all Unicode text is doing more than strict ASCII encoding. Its label alone does not establish what happens outside the ASCII range.

ASCII Table: All 128 Character Codes in Decimal, Hex, and Binary
Use this ASCII code table to find a character's decimal code, two-digit hexadecimal code, and binary representation. Standard ASCII is a seven-bit character set with values 0–127. The ASCII binary values below use an eight-bit byte display, so the first bit is always zero.
For manual conversion, locate the source character and copy its hex value. To convert ID=42, for instance, use the rows for I, D, =, 4, and 2, then keep those values in the same order. The decimal column lets you check an ASCII decimal-to-hex calculation without confusing the character with the number it spells.
ASCII Control Characters: Decimal 0–31
These are non-printing codes, so the symbol column shows a standard abbreviation and its meaning. They still occupy bytes when present in the input. HT, LF, and CR are especially useful when checking tabs and line endings.
Decimal Code | Hex Code | Binary (8-bit display) | Symbol / Meaning |
0 |
|
| NUL: Null |
1 |
|
| SOH: Start of heading |
2 |
|
| STX: Start of text |
3 |
|
| ETX: End of text |
4 |
|
| EOT: End of transmission |
5 |
|
| ENQ: Enquiry |
6 |
|
| ACK: Acknowledge |
7 |
|
| BEL: Bell |
8 |
|
| BS: Backspace |
9 |
|
| HT: Horizontal tab |
10 |
|
| LF: Line feed |
11 |
|
| VT: Vertical tab |
12 |
|
| FF: Form feed |
13 |
|
| CR: Carriage return |
14 |
|
| SO: Shift out |
15 |
|
| SI: Shift in |
16 |
|
| DLE: Data link escape |
17 |
|
| DC1: Device control 1 |
18 |
|
| DC2: Device control 2 |
19 |
|
| DC3: Device control 3 |
20 |
|
| DC4: Device control 4 |
21 |
|
| NAK: Negative acknowledge |
22 |
|
| SYN: Synchronous idle |
23 |
|
| ETB: End of transmission block |
24 |
|
| CAN: Cancel |
25 |
|
| EM: End of medium |
26 |
|
| SUB: Substitute |
27 |
|
| ESC: Escape |
28 |
|
| FS: File separator |
29 |
|
| GS: Group separator |
30 |
|
| RS: Record separator |
31 |
|
| US: Unit separator |
ASCII Printable Characters: Decimal 32–126
This ASCII to hex table covers space, punctuation, digits, uppercase letters, and lowercase letters. Space is labeled explicitly because an empty cell would hide it. The remaining symbols are the actual ASCII printable characters, with letter case preserved.
Decimal Code | Hex Code | Binary (8-bit display) | Character |
32 |
|
| SPACE |
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
|
| ` |
97 |
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
|
The Final Standard ASCII Code: DEL
Decimal Code | Hex Code | Binary (8-bit display) | Symbol / Meaning |
127 |
|
| DEL: Delete |
The ASCII hex values for decimal digits run from 30 to 39; uppercase letters use 41–5A, and lowercase letters use 61–7A. Values 128–255 are not part of this standard ASCII table. If a tool offers an extended table, check which eight-bit encoding it uses before applying those additional mappings.
How to Convert ASCII Text to Hex by Hand
Use the source string ID=42. It contains five characters, with no spaces or line break.
Source Character | ASCII Decimal | Hexadecimal Byte |
I | 73 |
|
D | 68 |
|
= | 61 |
|
4 | 52 |
|
2 | 50 |
|
Read down the last column to get 49 44 3D 34 32. Without display separators, the output is 49443D3432.
If you have decimal ASCII values rather than a hex table, divide each value by 16. The quotient gives the first digit and the remainder gives the second. Remainders ten through fifteen become A–F.
For the equals sign:
61 ÷ 16 = 3 remainder 13 → 3D
Keep two digits for every byte. A tab has decimal code 9, so its hex representation is 09, not a lone 9 in a byte-oriented output.
Do not convert the number 42 as one integer in this example. The source contains the text characters 4 and 2, which become 34 32. Decimal integer 42 would instead be hexadecimal 2A. The input's type determines the operation.

Use an Online Converter Without Changing the Message
An ASCII text to hex converter can save time, especially when the message includes several punctuation marks or repeated spaces. The useful settings are the input encoding, output delimiter, prefix, and letter case.
- Paste the exact source text into the input field.
- Select ASCII if the tool offers a strict encoding choice.
- Choose continuous output or a separator the destination accepts.
- Check any prefix setting, such as
0xper byte. - Convert, then compare the result with a known example.
Use ID=42 as a quick check: the bytes should be 49 44 3D 34 32. If the result includes another 20, the input may have a space. An ending 0A suggests a line feed.
Choose the conversion direction explicitly when the tool has automatic detection. The text FACE consists entirely of valid hexadecimal digits, so an auto-detect feature might decode it instead of encoding its four ASCII characters. Text mode should produce 46 41 43 45.
For private input, review the tool's processing and retention information. Do not assume that a converter runs locally just because it appears in a browser.
Python ASCII to Hex with Strict Input Checking
Python provides a direct way to reject non-ASCII characters before creating hexadecimal bytes:
message = "ID=42"
data = message.encode("ascii", errors="strict")
print(data.hex()) # 49443d3432
print(data.hex(" ").upper()) # 49 44 3D 34 32The first operation creates the encoded bytes. The .hex() method then displays those bytes in base 16. Uppercasing changes the presentation of hex letters without changing the represented data.
To produce a byte array initializer:
print(", ".join(f"0x{byte:02X}" for byte in data))
# 0x49, 0x44, 0x3D, 0x34, 0x32The 02X format keeps each byte two digits wide. That matters for low-valued control codes.
If the source includes a non-ASCII character, .encode("ascii") raises UnicodeEncodeError. Preserve that failure when the receiving system requires ASCII. Using errors="ignore" removes unsupported characters; errors="replace" substitutes them. Either option changes the original message.
For a text file whose contents must already be ASCII, inspect the bytes without normalizing line endings:
from pathlib import Path
raw = Path("request.txt").read_bytes()
raw.decode("ascii") # Validate; raises an error for non-ASCII bytes.
print(raw.hex())Reading bytes also preserves an existing final newline. Validate and inspect it rather than stripping it automatically.
JavaScript ASCII to Hex in Browsers and Node.js
A reusable conversion function should validate the ASCII limit before formatting each code. For ASCII input, JavaScript's UTF-16 code units match the required character values.
function asciiToHex(text, separator = " ") {
const pairs = [];
for (let index = 0; index < text.length; index++) {
const value = text.charCodeAt(index);
if (value > 0x7f) {
throw new Error(`Non-ASCII character at index ${index}`);
}
pairs.push(value.toString(16).padStart(2, "0").toUpperCase());
}
return pairs.join(separator);
}
console.log(asciiToHex("ID=42"));
// 49 44 3D 34 32
console.log(asciiToHex("ID=42", ""));
// 49443D3432The validation makes this a strict ASCII operation. Removing it would allow larger UTF-16 code-unit values, which are not a general substitute for encoded Unicode bytes.
In Node.js, validate first and use a Buffer for the conversion:
function asciiToHexNode(text) {
if (/[^\x00-\x7f]/.test(text)) {
throw new Error("Expected ASCII-only input");
}
return Buffer.from(text, "utf8").toString("hex");
}
console.log(asciiToHexNode("ID=42")); // 49443d3432UTF-8 produces the correct bytes here because validation has limited the input to ASCII. Do not rely on Node's 'ascii' encoding name to provide strict rejection: its legacy behavior differs from Python's strict ASCII encoder.
Generate Plain Hex from a Shell or File
On systems with xxd installed, this command converts a short literal without appending a newline to the input:
printf '%s' 'ID=42' | xxd -p
The output is 49443d3432. The newline that terminates the displayed result is not an extra encoded byte in the message.
Use a fixed printf format such as %s and pass the text separately. This prevents percent signs in the source from being interpreted as formatting instructions. A shell variable can be supplied as printf '%s' "$message".
If xxd is unavailable, a system with od can show the same bytes:
printf '%s' 'ID=42' | od -An -v -tx1
This produces space-separated values 49 44 3d 34 32, with possible layout whitespace. The options suppress the address column, show repeated data, and select one-byte hexadecimal output.
For an existing file:
xxd -p request.txt
This displays the file's existing bytes. It does not verify that those bytes belong to ASCII. For strict ASCII validation, use the Python file example before accepting the output.
The -p option selects plain hex rather than a dump with address offsets and a readable sidebar. Long output may be line-wrapped; whether to remove those display breaks depends on the destination. Preserve actual newline bytes that are part of the source message.
Pick the Hex Output Format Your Destination Expects
String to hexadecimal conversion does not have one universal display layout. The same five bytes can appear in several forms:
Output Style | Example for | Typical Purpose |
Continuous |
| A field requiring uninterrupted hex |
Space-separated |
| Human inspection |
Comma-separated constants |
| Code initializer elements |
Backslash escapes |
| A compatible escaped literal |
Prefixes, commas, and backslashes are notation. A receiver that expects raw hexadecimal digits may reject them, even though they describe the correct values elsewhere.
For n ASCII characters, including any control characters, the encoded message contains n bytes. Continuous hex therefore has 2 × n digits, excluding prefixes and separators. Five characters give ten digits.
Also check whether the destination expects hex text or raw bytes. These are different payloads. For the source OK, the original ASCII bytes are 4F 4B. Their continuous hex representation is the four-character string 4F4B.
If you send that representation as ordinary ASCII text, the transmitted bytes are 34 46 34 42, which spell the four digits and letters. If you parse the hex and send the resulting bytes, the transmitted data is the original two-byte message. A serial terminal or API may offer separate “text” and “hex” input modes, so choose the mode that matches its documentation.
Do not add a null terminator unless the interface requires one. Some programming environments use a zero byte to mark the end of a string, but that convention does not make 00 part of every ASCII message. An extra terminator changes the payload length and may affect how the receiver processes it.
An actual space in the source contributes byte 20. A space inserted between displayed byte pairs only helps readability. Keep those two roles separate when checking output length.
Verify the Result and Diagnose Extra Bytes
A round-trip check converts the hex back into bytes and decodes them using ASCII:
hex_output = "49443D3432"
recovered = bytes.fromhex(hex_output).decode("ascii")assert recovered == "ID=42"
That confirms the complete message, including case and punctuation, survived. For longer data, compare byte counts as well as the recovered text.
Line endings deserve special attention when preparing commands. The five visible letters and symbols are not always the whole message. For example, PING followed by carriage return and newline becomes:
50 49 4E 47 0D 0AThe printable word uses four bytes; the two control characters bring the total to six. A device expecting that ending may reject a message containing only 0A or no ending at all.
Inspect the original source when every conversion method produces the same unexpected bytes. A UTF-8 file saved with a byte order mark begins with EF BB BF, which is outside ASCII. A strict ASCII check should reject those bytes rather than hide them. Confirm the file's required encoding before removing a marker or resaving it.
Other clues include 09 for a tab, 00 for a null byte, and an unexpected final 20 for a trailing space. A tool may display control bytes as dots or escapes rather than visible characters.
Avoid “fixing” output by deleting unfamiliar pairs. First compare them with the input and the protocol's requirements. A missing control character can be just as harmful as an unwanted one.

Practical Questions About ASCII-to-Hex Conversion
Does conversion preserve spaces and tabs?
Yes, when the encoder processes the source unchanged. A space becomes 20, and a tab becomes 09. These bytes belong to the message, unlike separators added between hex pairs for readability. Check whether the tool trims input or whether an earlier copy-and-paste step changed tabs into spaces before encoding.
Can I convert emojis or accented characters as ASCII?
Strict ASCII cannot represent them. Choose an encoding supported by the destination, commonly UTF-8, or revise the source to valid ASCII if the protocol requires it. That is an explicit input decision. Do not silently discard unsupported characters and assume the resulting hex still describes the original message.
How do I convert decimal ASCII codes into hex?
Treat each decimal code as a separate character value between 0 and 127, then format it as a two-digit hexadecimal number. The list 79, 75 becomes 4F 4B, representing OK. Encoding the literal text 79, 75 instead would also encode the digits, comma, and space, producing a different result.
Why does my result end with 0A?
Hex 0A is a line feed. It often appears because the input has a final newline or a command generated one before conversion. Inspect the original file or string rather than assuming the converter added it. Some commands require that byte, so remove it only when the receiving format excludes it.
Why do two ASCII-to-hex tools return different results?
Compare the input, encoding, delimiters, prefixes, and letter case. Different display styles can describe identical bytes. Differences in the byte values can indicate trimmed whitespace, altered line endings, or non-ASCII input handled differently. Start with a small known string, then compare the actual pairs rather than the overall visual layout.
Can I turn the hex output back into ASCII?
Yes. Parse complete hex pairs into bytes and decode those bytes using ASCII. A strict decoder rejects byte values above 7F, even if they form valid hexadecimal pairs. If the original message used another encoding, use that same encoding for decoding. Hex to ASCII is reversible when the input and encoding remain intact.
Does ASCII-to-hex conversion make the output smaller?
No. Each source byte becomes two hexadecimal digits. If you store those digits as ASCII or UTF-8 text, continuous hex uses twice the original byte count, before any separators. It helps people inspect and exchange byte values; it is not compression, encryption, or a way to hide readable content securely.
Preserve the Message Before Formatting It
Knowing how to convert ASCII text to hex is most useful when you also verify what was encoded. Reject unsupported characters, preserve meaningful whitespace, and match the receiving format. Then decode the result once to confirm that the text and byte count agree with the original message.