Hexadecimal (base-16) is how developers write binary data in a form humans can read, copy, and diff. One hex digit is four bits; two hex digits are one byte. That is why memory dumps, color codes, hashes, and packet captures are full of values like B4, FF D8 FF, or 48656c6c6f.
This article explains what hex encoding is, when to use it, and the mistakes that waste the most time. For hands-on conversion, use Hex to String, String to Hex, Hex to Binary, or Hex Calculator.
Decimal, binary, and hex
Decimal (base-10) is everyday counting. Binary (base-2) is what machines store. Hex (base-16) sits in between: digits 0–9 and A–F (ten through fifteen).
- Binary byte:
10110100 - Same value in hex:
B4
Because 16 = 24, grouping bits into nibbles is clean. Developers rarely edit long bit strings by hand; they edit hex instead.
What “hex encoding” means in practice
Encoding a string or blob as hex does not compress or encrypt it. It changes representation: each byte becomes two printable characters (00–FF).
Text (UTF-8): Hello
Bytes: 48 65 6c 6c 6f
Hex string: 48656c6c6fDecode reverses the path: hex → bytes → (optional) character decoding.
Why developers convert to hex
Debugging opaque data
Raw bytes printed to a console look like noise or break the terminal. Hex lets you confirm null bytes, headers, and unexpected values without guessing.
Safe text transport
JSON, logs, and many config formats prefer printable text. Encryption keys, file signatures, and binary protocol fields are often shown as hex so they can be pasted safely.
File and protocol signatures
Examples you will see constantly:
- JPEG starts with
FF D8 FF - PNG starts with
89 50 4E 47(.PNG) - IPv4 addresses sometimes appear as 8 hex digits in dumps — convert with Hex to IP
Hashes, checksums, and API material
SHA-256 outputs 32 bytes. Those bytes are almost always displayed as a 64-character hex string. Matching two hex digests is how release pages verify downloads.
Web colors and percent-encoding
CSS colors such as #0F5C8C are hex channel values. URL percent-encoding uses hex too (%20 for space). Related tools: Hex to RGB and RGB to Hex.
Minimal examples
text = "Hello, World!"
hx = text.encode("utf-8").hex()
print(hx)
print(bytes.fromhex(hx).decode("utf-8"))const text = "Hello, World!";
const hx = Buffer.from(text, "utf8").toString("hex");
console.log(hx);
console.log(Buffer.from(hx, "hex").toString("utf8"));Pitfalls worth remembering
- Encoding matters: hex encodes bytes. Decode with the same character encoding used when the bytes were produced (usually UTF-8).
- Hex expands size: one byte → two characters. It is for readability and transport, not compression.
- Odd length is invalid: hex text must come in pairs unless a specific format defines padding rules.
- Case is usually irrelevant:
deadbeefequalsDEADBEEF, but stay consistent in APIs. - Whitespace: some APIs ignore spaces; others do not. Normalize before parsing.
Language guides on this site
- PHP hex to string · PHP hex2bin()
- Python hex to string (methods) · bytes.fromhex() deep dive
- JavaScript · Java · C#
Hex is a notation layer over binary. Once you treat it that way—bytes first, text second—most conversion bugs become obvious.