Skip to content

↑↓ navigate ↵ open Esc close Search runs locally

Hex Encode & Decode Online (Text ↔ Hex)

Convert text or files to hexadecimal bytes and hex back to text. Choose plain, spaced, colon or 0x formats, and decode hex dumps with any separator.

  • Runs in your browser
  • Nothing is uploaded
  • Free, no sign-up
0 BUTF-8
Hex
Runs in your browser. Nothing is uploaded. Tip: drop a file onto the left box

How to use the Hex (Base16) tool#

  1. Choose Encode to turn text or a file into hex, or Decode to turn hex back into text or a file.
  2. Type or paste into the left box. Each byte becomes exactly two hex digits.
  3. Pick a Format for the output: no separator, spaces, colons, 0x prefixes or \x escapes, and lowercase or uppercase.
  4. When decoding, separators such as spaces, colons, commas, 0x and \x are ignored automatically. Copy or download the result.

Examples#

Text to hex

Input
dev247
Output
646576323437

d is 0x64, e is 0x65, v is 0x76, and the digits 2, 4, 7 are 0x32, 0x34 and 0x37.

Hex with spaces back to text

Input
48 65 6c 6c 6f
Output
Hello

Spaces, colons and 0x prefixes are all accepted when decoding.

A UTF-8 character

Input
é
Output
c3a9

Characters outside ASCII take more than one byte in UTF-8. é is two bytes: 0xC3 and 0xA9.

Decode a 0x byte list

Input
0x48 0x69 0x21
Output
Hi!

Byte lists like this often come from C arrays, debuggers and protocol docs.

What is hex encoding?#

Hex encoding, also called Base16, writes every byte as two hexadecimal digits from 0–9 and a–f. One hex digit stands for 4 bits (a "nibble"), so two digits describe one byte exactly: 00 is 0 and ff is 255. Text to hex means: convert the text to bytes (UTF-8 on this page), then write each byte in hex.

Hex doubles the size of the data, which makes it bigger than Base64. In return, it is easy to read: you can see every byte, line up values, and spot patterns at a glance. That is why debuggers, hash functions and network tools show data in hex.

How hex maps to bits#

HexBitsDecimalHexBitsDecimal
000000810008
100011910019
200102a101010
300113b101111
401004c110012
501015d110113
601106e111014
701117f111115

For example, the letter H is byte 72. In bits that is 0100 1000, and the two nibbles 0100 and 1000 are 4 and 8, so H is 48 in hex.

Common hex formats#

The bytes are always the same, but different tools write them differently:

FormatExample for Hi!Where you see it
Plain486921Hashes, keys, API values
Spaced48 69 21Hex dumps, packet captures
Colon-separated48:69:21MAC addresses, certificate fingerprints
0x prefix0x48 0x69 0x21C/C++ arrays, debuggers
\x escapes\x48\x69\x21String literals in Python, PHP, JavaScript, shell
Percent-encoding%48%69%21URLs (only for unsafe characters)

Hex digits are not case-sensitive: c3a9 and C3A9 are the same bytes. Lowercase is the convention for hashes; uppercase is common in hardware and network documentation.

Text to hex and character encodings#

Hex shows bytes, not characters, so the result depends on how the text is turned into bytes. This tool uses UTF-8, the encoding used by the web, JSON and most APIs:

  • ASCII characters (A–Z, digits, punctuation) are 1 byte each: A → 41.
  • Accented Latin letters are usually 2 bytes: é → c3 a9.
  • Most other scripts and symbols are 3 bytes: ☕ → e2 98 95.
  • Emoji are usually 4 bytes: 😀 → f0 9f 98 80.

If another tool shows e9 for é, it is using Latin-1 (ISO-8859-1) instead of UTF-8.

Where hex is used#

  • Hashes and checksums: a SHA-256 hash is 32 bytes, shown as 64 hex characters. Try the hash generator.
  • Colors: #ef4444 is three bytes of red, green and blue.
  • MAC addresses and fingerprints: colon-separated bytes.
  • Debugging binary data: hex dumps of files, network packets and memory.
  • Keys and tokens: random secrets are often generated as hex strings.
  • Escape sequences: \x00 for bytes that cannot be typed.

Hex in code#

JavaScript#

javascript
// Browser: text → hexconst hex = Array.from(new TextEncoder().encode('Hi!'), (b) => b.toString(16).padStart(2, '0')).join(''); // "486921" // Browser: hex → textconst bytes = Uint8Array.from(hex.match(/../g), (h) => parseInt(h, 16));const text = new TextDecoder().decode(bytes); // Node.jsBuffer.from('Hi!').toString('hex');            // "486921"Buffer.from('486921', 'hex').toString('utf8'); // "Hi!"

PHP#

php
$hex = bin2hex('Hi!');   // "486921"$text = hex2bin($hex);   // "Hi!"

Python#

python
hex_str = 'Hi!'.encode('utf-8').hex()        # "486921"spaced = 'Hi!'.encode().hex(' ')             # "48 69 21"text = bytes.fromhex('48 69 21').decode()    # "Hi!"

Command line#

bash
echo -n 'Hi!' | xxd -p          # 486921echo '486921' | xxd -r -p       # Hi!xxd file.bin | head             # hex dump with offsets and ASCIIhexdump -C file.bin | head      # the same, another classic format

Common errors and fixes#

  • hex2bin(): Hexadecimal input string must have an even length (PHP) or "odd number of hex digits"

    Every byte needs two digits, so one digit is missing or extra. A common cause is a dropped leading zero, such as 7 instead of 07.

  • ValueError: non-hexadecimal number found in fromhex() arg (Python)

    The input contains characters other than 0–9, a–f and spaces, such as 0x prefixes or colons. Remove them first, or paste the value here: this tool ignores common separators and points to the first invalid character.

  • The decoded text shows strange characters like é

    The bytes are UTF-8 but were read as Latin-1, or the other way round. Decode as UTF-8. If the original was written in another encoding, convert it to UTF-8 first.

  • Converting a number gives a different result than expected

    This tool converts bytes, not numbers. The text 255 becomes 323535 (three characters), while the number 255 is ff. Use a number base converter for numeric values.

  • The decoded result says "Binary data"

    The bytes are not valid text: they are probably a file, a hash or encrypted data. Use Download to save the bytes. Images also show a preview.

Frequently asked questions#

How do I convert text to hex?

Choose Encode and type your text. Each character is converted to its UTF-8 bytes, and each byte is written as two hex digits. Hi! becomes 486921.

Is hex the same as Base16?

Yes. RFC 4648 calls it Base16: 16 symbols (0–9 and A–F), each representing 4 bits, so two symbols represent one byte.

Why is hex output twice as long as the input?

Each byte (8 bits) needs two hex digits (4 bits each). Hex adds 100% to the size, compared with 33% for Base64.

Is hex case-sensitive?

No. ff, FF and Ff are the same value. Choose lowercase or uppercase with the Case option.

Can I decode a hex dump with spaces, colons or 0x?

Yes. Spaces, line breaks, colons, commas, hyphens, 0x prefixes and \x escapes are ignored when decoding.

Is my data uploaded?

No. The conversion runs entirely in your browser and nothing is sent to a server.

Your next tool is one search away.

Free, private developer tools that run in your browser. No signup, nothing uploaded, no waiting.

Browse all tools

Tip: press Ctrl D to bookmark dev247.