How To Decode Hex File
By Letters2NumbersConverter.com · May 14, 2026
How To Decode Hex File means converting hexadecimal byte values back into the text or binary data they represent — taking something like 48 65 6C 6C 6F and producing the readable string Hello. Whether you are inspecting a firmware image, examining network traffic, or just curious about what a hex dump says, this guide walks through every step: how the hexadecimal number system works, how hex values map to ASCII characters, how to decode by hand, and how to automate the process in JavaScript and Python.
What Is a Hex File?
A hex file (short for hexadecimal file, sometimes called a hex dump) is a way of representing raw binary data in a human-readable format. Because every possible byte value (0–255) can be written as exactly two hexadecimal digits, a hex dump makes it possible to inspect binary content without a specialist binary viewer.
Several common formats exist:
- Intel HEX (.hex) — a structured text format used for microcontroller firmware, EEPROM content, and programmable logic. Each line is a record with a defined structure (covered later in this guide).
- Motorola S-record (.srec, .mot) — similar to Intel HEX but uses a different record prefix and checksum scheme; common in embedded development for Freescale/NXP processors.
- Plain hex dumps — the output of tools such as
xxdorhexdumpon Linux/macOS. These are unstructured: each row shows an address offset followed by byte values in hex, often with a printable-ASCII preview column on the right.
When most people say "decode a hex file" they mean one of two things: converting a raw hex string (like the output of xxd) back into text, or parsing a structured Intel HEX or S-record file to extract the binary payload. This guide covers both.
The Hexadecimal Number System
Hexadecimal is a base-16 number system. Decimal uses digits 0–9 (ten symbols); hexadecimal extends this with six letters: A represents 10, B represents 11, C represents 12, D represents 13, E represents 14, and F represents 15.
A single hexadecimal digit can represent values from 0 to 15 — exactly four binary bits (a nibble). Two hex digits together represent eight bits — one byte — with values from 00 (decimal 0) to FF (decimal 255). This is why hex is so convenient for binary data: every byte maps to exactly one two-character hex pair, no more, no less.
To convert a two-digit hex value to decimal, multiply the first digit by 16 and add the second. For example:
48hex → 4 × 16 + 8 = 64 + 8 = 72 decimal41hex → 4 × 16 + 1 = 64 + 1 = 65 decimalFFhex → 15 × 16 + 15 = 240 + 15 = 255 decimal
How Hex Maps to ASCII Text
The ASCII standard assigns a numeric value (0–127) to each printable character and control code. Because these values fit inside one byte, every ASCII character can be written as a two-digit hex pair. Our guide to ASCII character encoding goes deeper into the history and structure of the standard; here we focus on the practical mapping.
Two quick examples to make this concrete:
48 65 6C 6C 6F→ Hello57 6F 72 6C 64→ World
ASCII Hex Reference Table
The table below covers the printable ASCII ranges you will encounter most often. Use our ASCII decoder tool to look up any value interactively.
| Character | Hex | Decimal | Character | Hex | Decimal |
|---|---|---|---|---|---|
| Space | 20 | 32 | a | 61 | 97 |
| 0 | 30 | 48 | b | 62 | 98 |
| 1 | 31 | 49 | c | 63 | 99 |
| 2 | 32 | 50 | d | 64 | 100 |
| 3 | 33 | 51 | e | 65 | 101 |
| 4 | 34 | 52 | f | 66 | 102 |
| 5 | 35 | 53 | g | 67 | 103 |
| 6 | 36 | 54 | h | 68 | 104 |
| 7 | 37 | 55 | i | 69 | 105 |
| 8 | 38 | 56 | j | 6A | 106 |
| 9 | 39 | 57 | k | 6B | 107 |
| A | 41 | 65 | l | 6C | 108 |
| B | 42 | 66 | m | 6D | 109 |
| C | 43 | 67 | n | 6E | 110 |
| D | 44 | 68 | o | 6F | 111 |
| E | 45 | 69 | p | 70 | 112 |
| F | 46 | 70 | q | 71 | 113 |
| G | 47 | 71 | r | 72 | 114 |
| H | 48 | 72 | s | 73 | 115 |
| I | 49 | 73 | t | 74 | 116 |
| J | 4A | 74 | u | 75 | 117 |
| K | 4B | 75 | v | 76 | 118 |
| L | 4C | 76 | w | 77 | 119 |
| M | 4D | 77 | x | 78 | 120 |
| N | 4E | 78 | y | 79 | 121 |
| O | 4F | 79 | z | 7A | 122 |
| P | 50 | 80 | |||
| Q | 51 | 81 | |||
| R | 52 | 82 | |||
| S | 53 | 83 | |||
| T | 54 | 84 | |||
| U | 55 | 85 | |||
| V | 56 | 86 | |||
| W | 57 | 87 | |||
| X | 58 | 88 | |||
| Y | 59 | 89 | |||
| Z | 5A | 90 |
Step-by-Step: Decode a Hex String to Text Manually
Let's decode the hex string 48 65 6C 6C 6F by hand. The same process applies whether the bytes are space-separated or written as a continuous string like 48656C6C6F.
- Step 1 — Split the hex string into two-character pairs.
48656C6C6F → 48 65 6C 6C 6FIf bytes are already space-separated, you can skip this step. - Step 2 — Convert each pair from base-16 to base-10.
48→ 4 × 16 + 8 = 7265→ 6 × 16 + 5 = 1016C→ 6 × 16 + 12 = 1086C→ 1086F→ 6 × 16 + 15 = 111
- Step 3 — Look up the ASCII character for each decimal value.
- 72 → H
- 101 → e
- 108 → l
- 108 → l
- 111 → o
- Step 4 — Concatenate all characters.
H + e + l + l + o = Hello
Decoding Hex in JavaScript
JavaScript provides two built-in functions that make hex decoding straightforward: parseInt(string, radix) to convert a hex pair to a decimal integer, and String.fromCharCode(n) to turn that integer into an ASCII character.
// Convert a single hex pair to a character
parseInt('48', 16) // → 72 (decimal)
String.fromCharCode(72) // → 'H'
// Decode a full hex string (space-separated or continuous)
function hexToText(hex) {
// Remove spaces and split into pairs
const pairs = hex.replace(/\s+/g, '').match(/.{1,2}/g) || []
return pairs
.map(pair => String.fromCharCode(parseInt(pair, 16)))
.join('')
}
hexToText('48 65 6C 6C 6F') // → 'Hello'
hexToText('57 6F 72 6C 64') // → 'World'
hexToText('48656C6C6F') // → 'Hello'The key call is parseInt(pair, 16) — the second argument 16 tells JavaScript to treat the string as a base-16 number. Without it, parseInt would default to base-10 and return incorrect results for values containing A–F.
Decoding Hex in Python
Python's standard library has first-class support for hex decoding. The cleanest approach uses bytes.fromhex(), which accepts a hex string (with or without spaces, as of Python 3.7) and returns a bytes object. Calling .decode() on that object gives you a Python string.
# Decode a continuous hex string
bytes.fromhex('48656C6C6F').decode('utf-8')
# → 'Hello'
# Spaces are also accepted in Python 3.7+
bytes.fromhex('48 65 6C 6C 6F').decode('utf-8')
# → 'Hello'
bytes.fromhex('57 6F 72 6C 64').decode('utf-8')
# → 'World'
# For a hex string from a variable:
hex_str = '48656C6C6F20576F726C64'
result = bytes.fromhex(hex_str).decode('utf-8')
print(result) # → 'Hello World'If the hex data does not represent valid UTF-8 (for example, it is a binary file or firmware image), .decode('utf-8') will raise a UnicodeDecodeError. In that case, use .decode('latin-1') to get a character for every byte value, or omit .decode() entirely and work with the raw bytes object.
Intel HEX File Format
The Intel HEX format is a structured text representation widely used for distributing microcontroller firmware, EEPROM images, and programmable logic device configurations. Unlike a plain hex dump, each line in an Intel HEX file is a self-contained record with a defined structure:
:LLAAAATT[DD...]CC
: — Start code (colon marks the beginning of every record)
LL — Byte count: number of data bytes in this record (hex)
AAAA — Address: 16-bit start address for the data (hex)
TT — Record type (hex):
00 = Data
01 = End Of File
02 = Extended Segment Address
03 = Start Segment Address
04 = Extended Linear Address
05 = Start Linear Address
DD... — Data bytes (LL pairs of hex digits)
CC — Checksum: two's complement of the sum of all bytes
in LL, AAAA, TT, and DD, truncated to one byteA typical data record looks like this:
:10 0100 00 214601360121470136007EFE09D2190140 45
Here 10 (hex) = 16 bytes of data, 0100 is the target memory address, 00 is the data record type, the next 32 hex characters are the 16 data bytes, and 45 is the checksum. Intel HEX files are not intended to be decoded as ASCII text — they contain binary machine code or raw memory images destined for a hardware programmer.
Common Tools for Hex Decoding
- Hex editors — HxD (Windows, free) and Hex Fiend (macOS, free) let you open any file, view its raw bytes in hex, and edit them. They also show the ASCII preview column so you can see readable text alongside the hex values.
- xxd (Linux/macOS) — a command-line tool that creates hex dumps and can reverse them. Run
xxd file.binto dump, andxxd -r hexdump.txt output.binto reverse a dump back to binary. - hexdump (Linux) — similar to xxd;
hexdump -C file.binprints both the hex values and a printable-ASCII representation on each line. - Online hex decoders — browser-based tools let you paste a hex string and see the decoded text instantly. Our ASCII decoder tool handles hex-to-text conversion without any software installation.
Common Pitfalls When Decoding Hex Files
Not every hex file contains readable text
This is the most common misunderstanding. Images (JPEG, PNG), executables (ELF, PE), audio files (MP3, WAV), and firmware binaries all contain non-text byte sequences. Decoding their hex as ASCII produces garbled characters or raises errors — not because something is wrong with your decoder, but because the data was never text in the first place. Always know the original data type before expecting readable output.
- Odd-length hex strings — a valid hex string always has an even number of characters (every byte is two digits). An odd-length string suggests truncation or a formatting error.
- Encoding assumptions — ASCII only covers code points 0–127. If the data uses extended characters (accents, emoji, non-Latin scripts), it is likely UTF-8, UTF-16, or another encoding. Decoding it as ASCII will misinterpret multi-byte sequences.
- Confusing Intel HEX data with raw binary — Intel HEX records contain a header, address, and checksum around the actual payload. You cannot simply decode the entire file as ASCII; you need to parse the record structure and extract only the data bytes.
- Byte order (endianness) — multi-byte values (16-bit integers, 32-bit floats) are stored in either little-endian or big-endian order. If you are decoding numeric data rather than text, byte order matters.
Frequently Asked Questions
What is a hex file?
A hex file (also called a hex dump) is a representation of binary data where each byte is shown as two hexadecimal digits (0–9, A–F). Common formats include Intel HEX (.hex), Motorola S-record (.srec), and plain hex dumps from tools like xxd or hexdump.
How do I decode a hex string to text manually?
Split the string into two-character pairs. Convert each pair from base-16 to decimal. Look up that decimal value in the ASCII table to find the character. Concatenate all characters. For example, 48 65 6C 6C 6F → 72, 101, 108, 108, 111 → Hello. Use our ASCII decoder tool to do this instantly in the browser.
How do I decode a hex file in Python?
Use bytes.fromhex(hex_string).decode('utf-8'). For example, bytes.fromhex('48656C6C6F').decode('utf-8') returns Hello. Python 3.7 and later also accept space-separated hex strings directly.
How do I decode hex in JavaScript?
Use parseInt(pair, 16) to convert each two-character hex pair to a decimal integer, then String.fromCharCode(n) to get the ASCII character. For example, String.fromCharCode(parseInt('48', 16)) returns H.
Can every hex file be decoded to readable text?
No. Images, executables, audio files, and firmware binaries are all stored as hex in a hex dump, but their bytes do not correspond to printable ASCII characters. Attempting to decode them as text will produce garbled output or encoding errors. Only hex data that originally came from a text source will produce readable results.
Related Tools and Guides
- ASCII Decoder Tool — paste a hex string and decode it to ASCII text instantly in the browser
- Base64 Encoder and Decoder — convert between Base64 and binary data; often used alongside hex encoding
- Understanding ASCII Character Encoding — a deeper look at the ASCII standard, control characters, and extended code pages