How to use the Hex Encoder
Encode text to hex in three steps:
1
Enter your text
Type or paste any text. The status bar shows both character count and UTF-8 byte count — these differ for non-ASCII characters.
2
Choose output format
Select plain (continuous), space-separated, 0x prefix (for code), \x prefix (for Python/C), or % URL encoding. Toggle uppercase/lowercase for hex digits.
3
Copy the hex output
Click Copy to grab the hex string for use in code, URLs, or documentation.
When to use this tool
Use this tool when you need the hexadecimal byte representation of text:
- →Converting strings to hex for use in Python bytes literals (b'\x48\x65\x6c\x6c\x6f') or C char arrays
- →Generating URL percent-encoded strings for embedding special characters in query parameters and URL paths
- →Creating hex dumps of text content for protocol documentation, binary format specifications, or debugging
- →Encoding strings as 0x-prefixed hex values for Solidity/Ethereum smart contract parameters
- →Verifying how multi-byte UTF-8 characters (accented letters, CJK, emoji) are represented at the byte level
- →Encoding text for transmission over protocols that require hexadecimal representation of binary data
Frequently asked questions
Q:Why does this tool show a UTF-8 byte count that's different from the character count?
Characters and bytes are not always the same in UTF-8. ASCII characters (code points 0–127) use 1 byte each — 'Hello' is 5 characters and 5 bytes. Characters in the Latin Extended range (128–2047) use 2 bytes — 'é' (U+00E9) is 1 character but 2 bytes (C3 A9 in hex). CJK characters (code points 2048–65535) use 3 bytes — '世' is 1 character but 3 bytes (E4 B8 96). Emoji and supplementary characters (above 65535) use 4 bytes — 😀 is 1 character but 4 bytes (F0 9F 98 80). This matters when allocating database columns, network buffers, or any system that counts bytes rather than characters.
Q:What is the difference between \x hex encoding and 0x hex encoding?
Both represent the same byte values in hexadecimal, but they're used in different programming contexts. \x prefix is used inside string literals in Python (b'\x48\x65\x6c\x6c\x6f'), C/C++ ('\x48\x65\x6c'), and Ruby. It's an escape sequence inside a quoted string. 0x prefix is used for standalone hex integer literals in C (0x48), JavaScript (0x48), SQL (0x48), and Solidity. It's not inside a string. When generating SQL hex literals or Ethereum ABI parameters, use 0x. When generating Python bytes or C string escapes, use \x.
Q:How does URL percent encoding (%) differ from other hex formats?
URL percent encoding (defined in RFC 3986) uses % followed by two uppercase hex digits to represent bytes in URLs. For example, space encodes to %20 (not +, which is form-encoding), ! to %21, and 😀 to %F0%9F%98%80 (its four UTF-8 bytes). Percent encoding is mandatory for characters outside the unreserved set (A–Z, a–z, 0–9, -, _, ., ~) when used in URL paths and query strings. This tool produces RFC 3986 percent-encoding using uppercase hex digits. Note: the + sign for spaces is only used in application/x-www-form-urlencoded format (HTML form submissions), not in general URL encoding.
Q:Why are multi-byte characters like emoji encoded as multiple hex pairs?
This tool encodes text as UTF-8 bytes — the industry-standard byte encoding for Unicode. UTF-8 represents characters above U+007F as 2–4 bytes to fit all Unicode code points into a byte stream. Each byte becomes one hex pair. The emoji 😀 (U+1F600) encodes to four UTF-8 bytes: F0 9F 98 80. The accented letter é (U+00E9) encodes to two bytes: C3 A9. Understanding this is important for: correctly sizing database VARCHAR fields (must store bytes, not characters), implementing binary protocols, and understanding why strlen() in C can return more than the visible character count.
Q:What is the hex value for common control characters?
Essential control character hex values: null=00, bell=07, backspace=08, tab=09, newline (LF)=0A, carriage return (CR)=0D, escape=1B, space=20, delete=7F. In network protocols: HTTP line endings use CR+LF = 0D 0A. The BOM (Byte Order Mark) for UTF-8 is EF BB BF. The null terminator in C strings is 00. Recognizing these values in hex dumps helps debug protocol issues, binary file parsing, and text encoding problems.
Q:Can I use this tool to encode binary file content as hex?
This tool reads files as text (using FileReader.readAsText), which means binary files may be corrupted if they contain sequences that don't form valid UTF-8. For text files (HTML, JSON, CSV, source code), the tool works perfectly. For true binary files (images, executables, archives), use the 'Hash File' option in the hash tools for checksums, or a dedicated binary hex dump tool that reads files as ArrayBuffer. The hex encoder is designed for text-to-hex conversion, not binary file hex dumps.