Hex Encode Decode

Convert text to hexadecimal and hex back to text directly in your browser.

Back to all tools on ToolForge

More in Encoding & Decoding

Text



Hex

About Hex Encode Decode

This hex converter helps you turn plain text into hexadecimal values and decode hex back into readable text. It is useful for debugging byte-level data, inspecting encoded payloads and learning how strings are represented in UTF-8.

Hex Encoding Formula

// Text to Hex conversion
function textToHex(text) {
  const encoder = new TextEncoder();
  const bytes = encoder.encode(text);
  return Array.from(bytes)
    .map(b => b.toString(16).padStart(2, '0'))
    .join(' ');
}

// Hex to Text conversion
function hexToText(hex) {
  const cleaned = hex.replace(/[^0-9a-fA-F]/g, '');
  const bytes = new Uint8Array(
    cleaned.match(/.{1,2}/g).map(byte => parseInt(byte, 16))
  );
  const decoder = new TextDecoder();
  return decoder.decode(bytes);
}

Hex Encoding Examples

Text Hexadecimal
Hello 48 65 6C 6C 6F
World 57 6F 72 6C 64
A 41
123 31 32 33
!@# 21 40 23

Common Hex Applications

Frequently Asked Questions

What is hexadecimal encoding?
Hexadecimal encoding converts binary data or text into base-16 representation using digits 0-9 and letters A-F. Each byte (8 bits) becomes two hex digits. For example, 'A' (ASCII 65) becomes 0x41, and 'Hello' becomes 48 65 6C 6C 6F.
Why use hexadecimal instead of binary?
Hexadecimal is more compact and human-readable than binary. One hex digit represents 4 bits (a nibble), and two hex digits represent one byte. This makes it ideal for representing memory addresses, color codes, binary protocols, and debugging byte-level data.
What are common use cases for hex encoding?
Common uses include: debugging binary data and network protocols, representing color values in CSS (#RRGGBB), viewing memory dumps and binary files, encoding binary data for text-based transmission, and working with cryptographic hashes and checksums.
How do I decode hex back to text?
Each pair of hex digits represents one byte. Convert each byte to its ASCII/UTF-8 character equivalent. For example, hex '48' = decimal 72 = ASCII 'H'. Spaces between hex pairs are optional and ignored during decoding.