Converting ASCII Text to Hexadecimal

Learn how to convert plain ASCII text into hexadecimal byte representation. Step-by-step guide with character table and practical encoding examples.

Conversion

Hex

54 65 73 74 20 31 32 33

ASCII

Test 123

Detailed Explanation

ASCII-to-hexadecimal conversion transforms each character in a text string into its corresponding two-digit hex value. This encoding is used when you need to represent text data in a format that is unambiguous and independent of character rendering, such as in network protocols, configuration files, or when writing to binary streams.

How the conversion works:

For each character in the input string, look up its ASCII code point, then express that decimal value as a two-digit hexadecimal number. Uppercase letters A through F are conventional, though lowercase is equally valid.

Step-by-step example — converting "Test 123":

  1. T → ASCII 84 → hex 54
  2. e → ASCII 101 → hex 65
  3. s → ASCII 115 → hex 73
  4. t → ASCII 116 → hex 74
  5. (space) → ASCII 32 → hex 20
  6. 1 → ASCII 49 → hex 31
  7. 2 → ASCII 50 → hex 32
  8. 3 → ASCII 51 → hex 33

Result: 54 65 73 74 20 31 32 33

Quick reference for common ranges:

  • Digits 0-9: 30 through 39 — simply add 30 to the digit value
  • Uppercase A-Z: 41 through 5A — starting at position 1 in the alphabet, add 40
  • Lowercase a-z: 61 through 7A — starting at position 1, add 60
  • Space: always 20

Output format variations:

Hex-encoded text can be formatted in several common ways depending on the use case:

  • Space-separated: 48 65 6C 6C 6F — most readable, used in hex editors
  • Colon-separated: 48:65:6C:6C:6F — common in MAC addresses and TLS
  • Backslash-escaped: \x48\x65\x6C\x6C\x6F — used in C strings and Python bytes
  • Prefix notation: 0x48 0x65 0x6C 0x6C 0x6F — used in programming languages
  • Continuous: 48656C6C6F — compact form for data transmission

When to use ASCII-to-hex encoding:

This conversion is frequently needed when crafting binary protocol messages, building escape sequences for shell commands, embedding byte literals in source code, or preparing test data for low-level systems. It is also the basis for URL percent-encoding, where special characters become %XX where XX is the hex value.

Use Case

Developers convert ASCII to hex when crafting raw protocol messages, embedding byte values in source code, or preparing test payloads for security testing and network debugging tools.

Try It — Hex Editor

Open full tool