How to Use Base64 Encoding in Real Projects
Learn practical, production-ready ways to use Base64 encoding: data URLs for images, JWT payloads, API tokens, and email attachments, with real code examples.
Aug 08, 2026
Convert text to hexadecimal and back. Supports uppercase/lowercase, with or without byte separators.
Hexadecimal (or hex) is a base-16 number system that uses sixteen distinct symbols: 0-9 to represent values 0-9, and A-F (or a-f) to represent values 10-15. Hex encoding converts binary data into a human-readable string of hex digits.
Each byte (8 bits) is represented by two hex digits. For example, the byte value 255 is represented as FF in hex, and the ASCII character A (decimal 65) is represented as 41.
Hex encoding uses 2 characters per byte (16×16 = 256 values), making the output twice the size of the input. Base64 uses 4 characters per 3 bytes (64×64×64×64 = 16M values), about 33% larger. Hex is more human-readable; Base64 is more space-efficient.
Yes, but this tool uses UTF-16 code units (JavaScript's native string encoding). Characters in the Basic Multilingual Plane (BMP) encode to 2 hex bytes per character. Supplementary characters (emojis, rare scripts) will encode to 4 hex bytes (2 surrogate pairs).
Yes. The decode function automatically handles hex strings with spaces, without spaces, or with 0x or \x prefixes. It strips non-hex whitespace and processes the remaining hex digits.
Non-hexadecimal characters (anything except 0-9, A-F, a-f, and whitespace) are ignored during decode. If no valid hex digits remain, the output will be empty.
A byte is 8 bits. Each hex digit represents 4 bits (0-15). So 8 bits ÷ 4 bits per hex digit = 2 hex digits per byte. The maximum value FF (hex) = 255 (decimal) = 11111111 (binary).
JavaScript
const text = "Hello";
const hex = [...new TextEncoder().encode(text)]
.map(b => b.toString(16).padStart(2, '0'))
.join('');
// "48656c6c6f"
Python
import binascii
# Text to hex
hex_str = binascii.hexlify(b"Hello").decode()
# "48656c6c6f"
# Hex to text
decoded = binascii.unhexlify(hex_str).decode()
Encode and decode Base64 strings
Encode and decode URL strings
Encode/decode HTML entities
Convert domain names to/from Punycode
Encode/decode text in various formats
Blog
Learn practical, production-ready ways to use Base64 encoding: data URLs for images, JWT payloads, API tokens, and email attachments, with real code examples.
Aug 08, 2026
Learn what an SMS counter is, how GSM 7-bit and UCS-2 encoding work, and why character count matters for SMS delivery and billing.
Jun 17, 2026
Learn the fundamentals of binary encoding, how computers represent data as 0s and 1s, and how to convert between binary and other formats.
Jun 16, 2026