Hex Encoder / Decoder
Convert text to hexadecimal and back with configurable delimiters.
Advertisement
Loading...
What this tool does
Hexadecimal (base-16) encoding represents each byte as two characters from the set 0-9 and a-f. It is used universally in low-level programming, debugging memory dumps, color codes in CSS, and inspecting binary file contents. This tool converts text to hexadecimal and back, with options for byte delimiters and case.
The encoder operates on the raw bytes of your input, so any text encoding (UTF-8, Latin-1, ASCII) is preserved correctly. The decoder accepts both spaced and continuous hex strings, and produces the original text. This is invaluable when working with binary protocols, hash outputs, or when you need to inspect the byte-level representation of a string.
Usage Example
// Encoding "Hi"
"Hi".split("").map(c => c.charCodeAt(0).toString(16).padStart(2, "0")).join(" ")
// "48 69"
// Decoding "48 69"
"48 69".split(" ").map(h => String.fromCharCode(parseInt(h, 16))).join("")
// "Hi"
// Common in CSS colors
"#FF5733"
// R: 0xFF (255), G: 0x57 (87), B: 0x33 (51)Common Edge Cases
- Hex strings must have an even number of characters; odd-length input indicates truncation or a missing nibble.
- Uppercase (A-F) and lowercase (a-f) letters are equivalent in hex; decoders should accept both.
- Non-ASCII characters in the input are encoded as their UTF-8 byte sequence, which may be 2-4 bytes per character. The hex output length depends on the input encoding.
- Hex is not a compression format. The output is always exactly twice the length of the input in bytes.
- Some protocols use little-endian byte order (least significant byte first), while hex dumps typically use big-endian. Always check the specification for your use case.
FAQ
- What is the difference between hex and Base64?
- Hex uses 16 characters and produces output that is exactly 2x the input size. Base64 uses 64 characters and produces output that is about 1.33x the input size. Base64 is more compact; hex is more human-readable.
- Can I decode hex with a 0x prefix?
- This tool expects raw hex without the 0x prefix. If your input has the prefix, strip it first: '0xFF' becomes 'FF'.
- Why are some bytes shown as FF or 7F?
- 0xFF is 255 in decimal (all bits set) and 0x7F is 127 (the maximum signed byte value). These values often appear in binary files, compressed data, or as padding bytes.
Advertisement