TToolbox
0x

Hex Encode/Decode

Convert between text and hex bytes

About this tool

Hexadecimal (Base16) encoding translates binary raw byte sequences into human-readable pairs of hex characters (`00` through `FF`). In low-level networking, firmware forensics, memory dumping, and cryptographic debugging, hex strings provide a deterministic representation of raw bytes free from control character corruption. This tool converts plain text and UTF-8 strings to and from hexadecimal notation locally, with customizable delimiter spacing (spaces, commas, colons) and optional `0x` prefixes.

How to Use This Tool (Step-by-Step)

1

Enter Text or Hex String

Paste your plaintext string or raw hexadecimal byte stream into the input pane. Delimiters and prefixes are auto-sanitized.

2

Configure Delimiters & Prefixes

Select output delimiter styling: single-space separated, comma-separated with `0x` prefixes, colon-delimited, or unspaced continuous stream.

3

Copy Converted Hex Stream

The converted hexadecimal output renders in real time. Copy the formatted byte stream directly into your source code or packet analyzer.

Full Lossless UTF-8 Byte Support

Seamlessly serializes multi-byte UTF-8 streams: encodes 3-byte CJK ideograms and 4-byte emojis with zero character corruption.

C/C++ Hex Array Formatting

Generates formatted C/C++ array byte buffers (`{ 0x48, 0x65, ... }`) ready for direct inclusion in embedded firmware source code.

100% Client-Side Air-Gapped

Byte manipulations execute strictly inside local browser memory. Sensitive packet payloads and network auth tokens remain 100% private.

Hex Encoding Gotchas & Embedded Systems Tips

  • •Always zero-pad bytes to two digits: Hex value `A` must be formatted as `0A`. Omitting leading zeros destroys byte stream boundary alignments.
  • •Endianness awareness: Hex strings display in Big-Endian network order. X86 CPU memory stores multibyte integers in Little-Endian format.
  • •Hex vs Base64 bandwidth tradeoffs: Base64 expands data size by 33%; Hex doubles data size (+100%). Use Base64 for bulk transfer and Hex for debugging.

Code & Transformation Examples

Classic ASCII & CJK to Hex Benchmark

Plaintext Input
• "Hello" (纯英文字符)
• "中国" (中文 UTF-8 字符)
Hexadecimal Byte Sequence
• "Hello" -> 48 65 6c 6c 6f (每个英文字符占 1 个字节)
• "中国"  -> e4 b8 ad e5 9b bd (每个汉字占 3 个字节,共 6 字节)
  - "中" 对应: E4 B8 AD
  - "国" 对应: E5 9B BD

* Hexadecimal byte streams represent the definitive atomic reality of all TCP/IP network packets in Wireshark analyzers.

JavaScript TextEncoder to Hex Implementation Snippet

Text to Hex Function
function textToHex(str) {
  const bytes = new TextEncoder().encode(str);
  return Array.from(bytes)
    .map(b => b.toString(16).padStart(2, '0'))
    .join(' ');
}
Hex to Text Function
function hexToText(hexStr) {
  const clean = hexStr.replace(/[^0-9a-fA-F]/g, '');
  const bytes = new Uint8Array(clean.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
  return new TextDecoder().decode(bytes);
}

* Standard `TextEncoder` and `TextDecoder` APIs provide robust native UTF-8 multi-byte transcoding without third-party libraries.

Frequently Asked Questions

Q: Why is hex case-insensitive during decoding?

A: Hex uses 16 symbols where lowercase `a` and uppercase `A` both represent numeric 10 identically. The decoder parses both interchangeably.

Q: What happens if an odd number of hex characters is provided?

A: Bytes mandate character pairs. Odd-length streams indicate truncated inputs. The tool flags warnings and can pad trailing zeroes for debugging.

Q: Can this tool handle massive hex memory dumps?

A: Powered by native TypedArrays (`Uint8Array`), multi-megabyte hexadecimal memory traces serialize in milliseconds without UI freezing.

Related Tools

All processing happens locally in your browser. Your data is never uploaded to a server.
/