TOP

Free browser-based hexadecimal converter

ASCII to Hex Converter

Convert ASCII text into hexadecimal byte values instantly. Use UTF-8 Bytes when your text includes accents, non-Latin scripts, symbols, or emoji.

No signup Free online conversion

Interactive tool

Convert ASCII characters to hexadecimal

Ready

Output layout

ASCII mode emits one two-digit hex byte per character and marks unsupported characters instead of guessing an encoding.

Conversion guide

How to Convert ASCII to Hex

Each ASCII character has a numeric value from 0 to 127. Convert that value from decimal to base 16 and pad it to two digits. The capital letter A is decimal 65, so its hexadecimal byte is 41.

The converter repeats this for every character, including spaces and control characters. For example, Hi becomes 48 69. Spaced output makes byte boundaries clear, while compact output represents the same bytes as 4869.

CharacterASCII decimalHex byte
A6541
B6642
a9761
04830
Space3220

ASCII to Hex in JavaScript

JavaScript can read each character with charCodeAt, reject values above 127, convert the value with toString(16), and use padStart(2, "0") to produce a complete hex byte.

function asciiToHex(text) {
  return Array.from(text, (character) => {
    const value = character.charCodeAt(0);
    if (value > 127) throw new Error("Non-ASCII character");
    return value.toString(16).padStart(2, "0").toUpperCase();
  }).join(" ");
}

asciiToHex("Hi");
// 48 69

ASCII to Hex in Python

Python's ord returns the numeric value of a character, and format(value, "02X") writes an uppercase two-digit hex byte. Checking every value below 128 keeps the result strictly ASCII.

def ascii_to_hex(text):
    if any(ord(char) > 127 for char in text):
        raise ValueError("Non-ASCII character")
    return " ".join(format(ord(char), "02X") for char in text)

print(ascii_to_hex("Hi"))
# 48 69

ASCII Hex vs UTF-8 Hex

Standard ASCII covers code points 00 through 7F, so every ASCII character maps to one hex byte. ASCII is also a subset of UTF-8, which means English letters, digits, punctuation, and control characters produce identical hex in both modes.

Characters above U+007F are not ASCII. In UTF-8 they may use multiple bytes: é becomes C3 A9, and becomes E4 BD A0. Use UTF-8 Bytes for multilingual text, symbols, or emoji.

One ASCII character equals one two-digit hex byte.

This rule is reliable only for standard ASCII. UTF-8 may use two, three, or four hex bytes for one Unicode character.

ASCII to Hex Output Formats

The bytes for Hi can be written as spaced hex 48 69, compact hex 4869, prefixed values 0x48 0x69, or byte escapes \x48\x69. The underlying byte values do not change.

Use spaced output for inspection, compact output for storage or protocols, 0x prefixes in programming contexts, and byte escapes in source strings or debugging fixtures.

Advertisement

Sponsored link