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 uses0aalone. A stray0dat the end of each line explains many failed string comparisons and broken shell scripts. - Byte order marks. A file starting with
ef bb bfhas a UTF-8 BOM, which can break JSON parsers, CSV headers, and shebang lines. - Invisible spaces. A non-breaking space appears as
c2 a0rather than the ordinary20, 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
\x41in C, Python, and shell scripts use hex byte values. - Hex dumps from tools like
xxdandhexdump, packet captures, and serial protocol logs. - MAC addresses, memory addresses, and file signatures (magic numbers) such as
25 50 44 46for%PDF.
Common confusion
- Text-to-hex is not number conversion. Encoding the text
255gives the bytes of the characters 2, 5, and 5 (32 35 35), notff. To convert a number between bases, use the Base Converter. - Formatting varies. Hex from other tools may include
0xprefixes, colons, commas, or no separators at all. This decoder strips0xand\xprefixes and ignores spaces, commas, colons, semicolons, and hyphens, so most formats can be pasted as they are. - Letter case does not matter.
C3A9andc3a9are the same bytes.
Conversion happens locally in your browser, live as you type.