Skip to content
ToolkitHub

Hex Encode/Decode

Hexadecimal encoder and decoder

Guide

Text to hexadecimal: reading the bytes

By Logappradeep · ServiceNow developer

Hexadecimal, or base 16, writes numbers with the digits 0–9 and the letters a–f. It is the standard way to show raw bytes because one byte (8 bits) fits exactly into two hex digits, each digit covering 4 bits, sometimes called a nibble. Converting text to hex shows you exactly which bytes a string contains, with nothing hidden by fonts, terminals, or editors.

How text becomes hex

The text is first encoded to bytes using UTF-8, then each byte is written as a two-digit hex value. ASCII characters take one byte each, so Hi becomes 48 69. Characters outside ASCII take two to four bytes: é becomes c3 a9, and an emoji like 😀 becomes four bytes, f0 9f 98 80. Decoding reverses the process, reading pairs of hex digits back into bytes and interpreting them as UTF-8 text. RFC 4648 calls this the Base16 encoding; it doubles the size of the data, which is fine for inspection but rarely used for storage.

Debugging problems that hex reveals

  • Line endings. Windows text uses 0d 0a (CR LF) while Unix uses 0a alone. A stray 0d at the end of each line explains many failed string comparisons and broken shell scripts.
  • Byte order marks. A file starting with ef bb bf has a UTF-8 BOM, which can break JSON parsers, CSV headers, and shebang lines.
  • Invisible spaces. A non-breaking space appears as c2 a0 rather than the ordinary 20, which is why some pasted text refuses to match.
  • Mojibake. When text shows up as é instead of é, the hex view confirms that the bytes are correct UTF-8 (c3 a9) and the problem is a program reading them with the wrong encoding.

Where hex appears in everyday development

  • Hash digests such as SHA-256, and many cryptographic keys and IDs, are displayed as hex strings.
  • Escape sequences like \x41 in C, Python, and shell scripts use hex byte values.
  • Hex dumps from tools like xxd and hexdump, packet captures, and serial protocol logs.
  • MAC addresses, memory addresses, and file signatures (magic numbers) such as 25 50 44 46 for %PDF.

Common confusion

  • Text-to-hex is not number conversion. Encoding the text 255 gives the bytes of the characters 2, 5, and 5 (32 35 35), not ff. To convert a number between bases, use the Base Converter.
  • Formatting varies. Hex from other tools may include 0x prefixes, colons, commas, or no separators at all. This decoder strips 0x and \x prefixes and ignores spaces, commas, colons, semicolons, and hyphens, so most formats can be pasted as they are.
  • Letter case does not matter. C3A9 and c3a9 are the same bytes.

Conversion happens locally in your browser, live as you type.

Frequently asked questions

Why does one character produce several hex pairs?

Characters outside ASCII take two to four bytes in UTF-8, and each byte is shown as its own two-digit pair.

Is this the same as converting a decimal number to hex?

No. This tool converts the bytes of text. To convert a number such as 255 to ff, use a base converter.

Why does decoding produce strange symbols?

The hex probably does not represent valid UTF-8 text, for example a hash or binary file data. Not every byte sequence is readable text.

Does upper or lowercase hex matter?

No. Hex digits are case-insensitive, so A9 and a9 represent the same byte.