Text to Hex Converter

Convert text into hexadecimal bytes.

Text to Hex Converter tool

About the Text to Hex Converter

Developers often need text as hexadecimal bytes for code, network protocols, test data or debugging. This text to hex converter encodes text as UTF-8 and writes each byte as two hex digits, in the format your tool expects: separated by spaces, colons or commas, with an optional 0x or \x prefix, in upper or lower case. Hello becomes 48 65 6C 6C 6F, while accented letters and emoji take two to four bytes each.

Each character is first encoded as UTF-8: characters in basic English are one byte, equal to their ASCII code, while others take two to four bytes. Each byte is then written as two hexadecimal digits, 0 to 9 and A to F, where A is 10 and F is 15. So H, code 72, is 48 in hex, because 4 × 16 + 8 = 72. With the \x prefix and no separator, the output can be pasted straight into a C, Python or JavaScript string.

Example: Hi! becomes 48 69 21, or 0x48, 0x69, 0x21 with prefixes and commas, which suits a C array. The letter é becomes C3 A9, and 😀 becomes F0 9F 98 80.

To decode hex back to text use the hex to text converter. For binary use the text to binary converter, for decimal character codes the text to ASCII converter, and for single numbers the decimal to hex converter.

How to use the Text to Hex Converter

  1. Type or paste textAny language, symbols and emoji.
  2. Choose the separatorSpace, none, colon, comma or new line.
  3. Choose prefix and caseNone, 0x or \x; uppercase or lowercase.
  4. Copy the hexPaste it into code, a hex editor or a protocol tool.

Text to Hex Converter features

  • UTF-8 bytes in hexadecimal
  • Space, colon, comma, newline or no separator
  • 0x or \x prefixes
  • Uppercase or lowercase digits
  • Any language and emoji
  • Byte count
  • Instant results

Common uses

  • Byte arrays for C, Python and JavaScript
  • Debugging encoding problems
  • Network protocol and API work
  • Hex editors and firmware
  • Computer science lessons

Text to hex in practice: byte arrays for microcontrollers, invisible spaces, byte order marks, SQL literals and Urdu bytes

By the FreeToolsWorld editorial team · Updated November 2026 · How we write and check our guides

Hex shows exactly which bytes a piece of text contains, which is what you need when writing data into firmware, hunting for invisible characters or inserting raw values into a database. This guide prepares a message for a microcontroller display, then uses hex to find invisible spaces, byte order marks and zero-width characters, and covers SQL hex literals, escape sequences and Urdu text.

A worked example: a message for a display

An Arduino project shows prices on a small LCD and stores fixed messages as byte arrays. The text Rs 500 converts to 52 73 20 35 30 30, written with prefixes and commas as 0x52, 0x73, 0x20, 0x35, 0x30, 0x30, ready to paste into the code. Six characters become six bytes, because every character here is basic ASCII.

Invisible spaces

Text copied from websites and documents often contains a non-breaking space instead of a normal one. Converting Rs 500 copied from a web page might give 52 73 C2 A0 35 30 30, where C2 A0 is the non-breaking space. The text looks identical on screen but fails exact matches, searches and validation. Hex reveals the difference instantly.

Byte order marks and zero-width characters

Some files begin with the bytes EF BB BF, a byte order mark, which can break scripts, CSV imports and JSON parsers expecting text to start immediately. Zero-width spaces, E2 80 8B, hide inside copied text and break usernames and URLs. Converting suspicious text to hex and looking for these sequences explains many mysterious failures.

Hex literals in SQL

Databases accept text written as hex, which is useful for inserting exact bytes or values with awkward characters. In MySQL, X'48656C6C6F' and 0x48656C6C6F both represent Hello. Writing values this way avoids quoting problems when testing how a database stores particular byte sequences.

Escape sequences

Many languages and regular expression engines accept hex escapes, such as \x41 for A. Converting a character to hex gives you the escape directly, which helps when a character is hard to type or invisible, such as a tab or a non-breaking space in a search pattern.

Urdu bytes

The Urdu word سلام converts to D8 B3 D9 84 D8 A7 D9 85, eight bytes for four letters, because each letter takes two bytes in UTF-8. Seeing the bytes helps estimate storage, check that a system is really storing UTF-8 and compare text that looks identical but uses different letter forms.

Counting bytes

Some limits are measured in bytes rather than characters, such as certain database fields, protocol headers and device memory. Converting text to hex and counting pairs gives the exact byte length, which can be much larger than the character count for Urdu text and emoji.

Hex in web addresses

Percent-encoding in URLs is hex in disguise: é becomes %C3%A9, the same C3 A9 bytes shown here, each preceded by a percent sign. Converting text to hex is a quick way to understand what an encoded address contains.

Common mistakes

  • Assuming one character is always one byte.
  • Missing non-breaking spaces in copied text.
  • Leaving byte order marks at the start of data files.
  • Comparing text visually instead of byte by byte.

Related tools

To decode hex back into text, use Hex to Text Converter. To percent-encode text for links, try URL Encoder, and to find or insert hidden characters, Invisible Text Generator.

Letters that look identical

Hex makes look-alike letters easy to tell apart. The Arabic form of yeh, ي, is D9 8A, while the Urdu form, ی, is DB 8C. Text typed on different keyboards may contain either, and searches, sorting and duplicate checks treat them as different. Converting both strings to hex shows exactly which form each one uses.

Line endings and tabs

Line endings are visible in hex: a Unix line ending is 0A, while Windows uses 0D 0A. A tab is 09 and a space 20. When a file behaves differently on two computers, or alignment looks wrong, converting a sample to hex shows which characters are really there.

Colour codes are not text bytes

A colour code such as FF0000 is already hex, describing a colour. Converting the text FF0000 with this tool gives 46 46 30 30 30 30, the bytes of the characters F, F and 0. Use colour converters for colour values and this tool only when you need the bytes of the text itself.

Preparing test data

When testing parsers and importers, include characters with special meaning: the double quote is 22, the backslash 5C, the comma 2C and the semicolon 3B. Converting test strings to hex confirms they contain exactly the characters intended, rather than look-alikes substituted by an editor.

Choosing a format for your code

Different destinations expect different hex styles: C and Arduino arrays use 0x prefixes with commas, Python byte strings use \x escapes, and many debugging tools expect plain pairs separated by spaces. Choosing the matching format here saves editing the output by hand before pasting it into code.

Privacy

Conversion runs in your browser. Your text is not uploaded or stored.

Frequently asked questions

How do I convert text to hex?

Encode each character as UTF-8 and write each byte as two hexadecimal digits. A is 41, a is 61, a space is 20 and 0 is 30. This converter does it for a whole text at once.

What is the hex code for a space?

20, because a space is character 32 in ASCII and 32 = 2 × 16. A new line is 0A, a tab is 09 and a carriage return is 0D.

Why does é become two hex bytes?

Because UTF-8 stores characters beyond basic English in two to four bytes. é is C3 A9 in UTF-8. In the older Latin-1 encoding it was the single byte E9.

What is the difference between 0x and \x?

Both mark a hexadecimal value. 0x is used for numbers in C, JavaScript and Python, as in 0x48, while \x is an escape inside strings, as in "\x48\x69".

Is hex the same as Base64?

No. Hex uses 2 characters per byte, Base64 about 1.33. Hex is easier for people to read byte by byte; Base64 is more compact for sending data.

Can I convert hex back to text?

Yes, with the hex to text converter, which accepts any separator and prefix, including the formats this tool produces. Paste the hex there and the original text appears, including accented letters and emoji.

Is my text sent to a server?

No. The conversion runs in your browser, so your text never leaves your device. Nothing is stored or logged, and the tool keeps working offline once the page has loaded, so it is safe for private text.

Why is hex used instead of binary?

Hex is far shorter and easier to read: every byte is exactly two hex digits instead of eight binary digits, and each hex digit stands for four bits, so converting between the two by eye is simple.

How do I convert text to hex in Python or JavaScript?

In Python, 'Hi'.encode('utf-8').hex() returns 4869. In JavaScript, encode the string with TextEncoder, then turn each byte into two hex digits with toString(16) and padStart(2, '0'). Both use UTF-8, like this tool.