Skip to content
ToolPlankDEV
Encoders & Decoders
100% In-Browser Execution

Updated:

Text to Hex Converter

Type or paste text and get its hexadecimal bytes. This text to hex converter writes spaced hex, a 0x list, a \x string or a SQL literal, supports UTF-8, ASCII, Latin-1 and UTF-16, and shows why one character can take several bytes. Nothing is uploaded.

Options:

Text

Input
0 chars · 0 lines

Hex

Ready
Processing in browser...
0 chars · 0 linesUpdates as you type

Bytes

A table of each character and its bytes appears here for texts up to 60 characters.

Processed on your device. Your text is not sent to our servers.

More free tools you may need next.

Quick Guide

How to use Text to Hex

Simple step-by-step instructions to get the exact output you need.

  1. 01

    Type or paste your text

    Type in the left box, press Paste, or open a text file. Sample loads a line with an accent, a euro sign and an emoji so you can see multi-byte characters.

  2. 02

    Pick the character set and format

    UTF-8 suits most text. Choose spaced hex for reading, or a 0x list, a \x string or a SQL literal to paste into code. Set bytes per line, uppercase or lowercase, and how line breaks are written.

  3. 03

    See where each byte comes from

    For text up to 60 characters, the Bytes panel lists every character with its code point and its bytes, so you can see why one character becomes several bytes.

  4. 04

    Copy or download

    Press Copy to use the hex, or Download to save it as hex.txt.

How to convert text to hex

Computers store text as bytes, and hex is a short way to write a byte: two digits from 00 to ff. To convert text to hex, the tool turns each character into bytes using a character set, then writes every byte as two hex digits. The word Hello becomes:

Text
48 65 6C 6C 6F

Each letter is one byte, so the status line reads 5 characters, 5 bytes, UTF-8. A line that holds more than plain English letters shows the difference. The sample, Hello, world! on one line and Café €5 followed by an emoji on the next, starts with the bytes 48 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21 0A, where 0A is the line break. The letter é and the symbols after it use more.

Why one character can be several bytes

UTF-8 uses one byte for the first 128 characters, which covers English letters, digits and common punctuation. Other characters take two, three or four bytes. For a text up to 60 characters, the Bytes panel lists them. For Aé followed by an emoji it shows:

Text
A   U+0041   41 · 1 byte
é   U+00E9   C3 A9 · 2 bytes
😀  U+1F600  F0 9F 98 80 · 4 bytes

The code point, written U+ and a hex number, is the character's identity in Unicode. The bytes are how a character set writes it down. Other sets write the same character differently. In UTF-16 little-endian the same text starts 41 00 and uses two bytes for é and four for the emoji. Switch the character set and the panel updates.

Text to hex in the format your code needs

A column of plain hex is fine for reading. For code, the Format menu writes the same two bytes of the word Hi in the shapes programmers use:

  • Spaced: 48 69
  • Continuous: 4869
  • 0x list: 0x48, 0x69, for a C or JavaScript array
  • \x string: "\x48\x69", for a C or Python string
  • Percent: %48%69, as in a URL
  • SQL literal: 0x4869, for MySQL and SQL Server binary values
  • SQL literal: X'4869', for MySQL and SQLite

Bytes per line breaks long output into rows of 8, 16 or 32. In the 0x list, each row ends with a comma, so you can paste it between braces. In the \x string every row is wrapped in quotes. Percent codes and SQL literals stay on one line. Uppercase letters is on by default. Turn it off for the lowercase style that Python and many languages print.

Text to hex with ASCII, Latin-1 and UTF-16

ASCII holds 128 characters. If your text has anything else, the tool stops and says which character and where, for example ASCII cannot hold "é" (U+00E9) at line 1, column 2. It does not replace the character with a question mark, because that would silently change your data. Latin-1 / Windows-1252 writes one byte for each character it knows, including é and the euro sign, and gives the same error for the rest. UTF-8 and UTF-16 hold every character.

Hex is only another way to write bytes. It is not encryption, and anyone can turn it back into text with Hex to Text.

Line breaks in the output

A line break is the byte 0A on Linux and macOS, and the two bytes 0D 0A on Windows. The input box keeps line breaks as 0A. If the hex has to match a Windows file or a protocol that uses CRLF, set Line breaks to Windows. The notes say when that was applied.

Text to hex in Python, JavaScript and on the command line

In Python, encode the string and call hex:

Python
print("Hello".encode("utf-8").hex(" "))

In JavaScript, TextEncoder gives the bytes, and the rest formats them:

JavaScript
Array.from(new TextEncoder().encode("Hello"), (b) => b.toString(16).padStart(2, "0")).join(" ")

On the command line, xxd -p prints plain hex:

Bash
printf 'Hello' | xxd -p

In Excel, DEC2HEX(CODE(A1)) gives the hex of one character. For whole strings, paste them here. For a different encoding of the same bytes, Base64 Encode and URL Encode write them as Base64 and percent codes, and File to Base64 does it for a file.

Limits

  • The tool encodes text. It does not read files, so use File to Base64 to turn a file into text.
  • Characters that a chosen character set cannot hold stop the conversion with an error.
  • An unpaired surrogate, which is not valid Unicode, is written by UTF-8 as EF BF BD and the notes say so.
  • Latin-1 here means Windows-1252, as in browsers. It differs from strict ISO-8859-1 only for the bytes 80 to 9f.
  • Very large input is limited to 2,000,000 characters.

Your text is converted in your browser. It is not uploaded or stored. See the Privacy Policy for details.

Frequently Asked Questions

Technical Q&A for Text to Hex

Common questions about edge cases, character encoding, and privacy guarantees.

Type or paste your text into the left box. The hex appears on the right at once. Press Copy or Download to use it.

Look up each character's byte value in a table such as ASCII, then write the value in base 16. The letter H is 72, which is 48 in hex. A is 65, which is 41.

UTF-8 uses one byte for English letters and digits but two to four for accents, symbols and emoji. The Bytes panel lists each character with its bytes so you can see it.

For plain English text they give identical bytes. ASCII cannot hold any other character, so it stops with an error. UTF-8 writes accents and emoji with extra bytes.

Choose it in the Format menu. The 0x list gives 0x48, 0x69 for an array, and the \x string gives "\x48\x69" for a C or Python string.

Encode the string to bytes and call hex, as in "Hello".encode("utf-8").hex(). Pass a separator such as a space to hex to get spaced output.

Use DEC2HEX(CODE(A1)) to get the hex of a single character. Excel has no built-in formula for a whole string or for UTF-8, so paste longer text here.

No. Hex only writes bytes in a different notation, and anyone can reverse it. Do not use it to protect secrets.

Yes. Set Line breaks to Windows and each line break becomes the two bytes 0D 0A instead of the single byte 0A.

No. The conversion runs in your browser and nothing is sent to a server.