Skip to content
Hex Calculator

Hex Escape Converter

Convert text into \xHH escape-sequence notation — ready to paste into a C, Python, or JavaScript string literal.

Escaped result
\x48\x69

How to Convert Text to \\xHH Escape Notation

Encode the text as UTF-8 bytes, then write each byte as \x followed by exactly 2 hex digits, with no separator between escapes — the standard format most languages expect inside a string literal.

Hex Escape Example, Step by Step

Hi = \x48\x69

"Hi" = \x48\x69

H -> 0x48 -> \x48
i -> 0x69 -> \x69
StepDescriptionResult
Encode to UTF-8 bytesH=0x48, i=0x692 bytes
Wrap each in \x notation\x48, \x692 escapes
Concatenateno separator between escapes\x48\x69

Common Mistakes With Hex Escape Notation

  • Adding a separator between escapes — the standard form has none.
  • Using 1 digit instead of 2 per escape, which some languages will misread.
  • Forgetting multi-byte UTF-8 characters produce several consecutive escapes, not one.

Frequently Asked Questions

What is \xHH notation?

A way of writing a single byte inside a string literal using its hex value — \x48 represents the byte 0x48 (the letter H) — supported directly in C, Python, JavaScript, and most other languages.

How is this different from Text to Hex?

Text to Hex gives a plain run of hex digits (48656C6C6F). This page wraps each byte in the \x escape format (\x48\x65\x6c\x6c\x6f) so the result can be pasted directly into a string literal in code.

What encoding produces the bytes being escaped?

UTF-8 — so plain English produces one \xHH escape per character, while accented letters, other scripts, and emoji produce 2-4 escapes per character.

Is \xHH the same in every language?

The notation itself is widely shared, but behavior can differ slightly — some languages (like Python) require exactly 2 hex digits after \x, while others accept a variable number. This converter always outputs exactly 2 digits per escape, the safest and most portable form.

Why escape text instead of just using it directly?

To embed raw bytes that aren't printable or safely typeable in source code, or to make the exact byte content of a string explicit and unambiguous in code review.

Can I decode \xHH escapes back to text?

Yes — use the Hexadecimal Escape Decoder, which reverses this exact conversion.