Hex Encode/Decode (Binary)

100% client-side processing (no server upload). Convert binary files to Hex text (plain, 0x…, C \xHH, or %HH) and decode Hex text back into a file with strict validation, separator handling, and predictable output formatting.

Loading…

About Hex Encode/Decode (Binary)

This tool converts binary files to Hex text and also decodes Hex text back into a binary file, entirely in your browser. Choose an action (Encode file β†’ Hex or Decode Hex β†’ file), pick the Hex format you want (plain, 0x…, C-style \xHH, or %HH), and control formatting details like letter case, byte separators, wrapping, and line endings. For decoding, you can accept common token styles (0x, \xHH, %HH), allow separators/whitespace, and optionally ignore non-hex characters or fail fast with strict validation.

Features

  • 100% client-side processing (no server upload).
  • Upload and batch-process multiple files via a dropzone (multi-file enabled).
  • Two actions: Encode file β†’ Hex text, or Decode Hex text β†’ file.
  • Hex output formats: plain (deadbeef), 0x… prefix, C escape (\xHH), and percent (%HH).
  • Letter case control: lowercase or uppercase hex digits.
  • Byte separators for readability: none, space, colon (:), dash (-), underscore (_), comma (,).
  • Encode-only wrapping: wrap bytes per line (0 disables wrapping) + selectable line separator (LF or CRLF).
  • Encode-only toggles: insert final newline; optional 0x per byte (0xDE 0xAD …) for 0x-style output.
  • Decode-only parsing controls: accept 0x prefix, accept \xHH escapes, accept %HH encoding, allow separators/whitespace, ignore non-hex characters, and odd-length handling (error or left-pad with 0).
  • Strict validation mode to reject malformed input early instead of best-effort parsing.

How to use for hex-binary-encoder

1

Drop a file or paste Hex text

For encoding, drop one or more binary files into the dropzone. For decoding, paste Hex text into the output editor (or drop a .hex/.txt file containing Hex).

2

Choose action and run

Select the Action: "Encode file β†’ Hex" or "Decode Hex β†’ file", then click the matching button (Encode/Decode). Configure options as needed: format (plain/0x/\xHH/%HH), case, separators, wrapping + line separator (encode), or accept-toggles + separator handling + odd-length rules (decode).

3

Copy or download the result

If you encoded, copy the generated Hex text from the editor or download it as a text output. If you decoded, download the reconstructed binary file (the tool strips a .hex suffix when possible and falls back to .bin).

Technical specifications

Execution Model

This tool runs entirely in your browser and does not upload your input to a server.

AspectDetail
Runtime100% client-side processing (no server upload).
Action scopeEncode (binary file β†’ Hex text) and Decode (Hex text β†’ binary file) on the same page.
InputEncode: binary (File/Blob/Uint8Array/ArrayBuffer/TypedArray). Decode: text (Hex string with optional tokens and separators).
OutputEncode: text (Hex). Decode: bytes (downloadable binary file).
Limits~1–2MB chars; ~25000 ms timeout
RetentionAll processing happens locally in your browser (no upload)
Even with local processing, avoid handling secrets you can't afford to expose (screen sharing, extensions, clipboard history, device compromise). For sensitive data or compliance workflows, prefer local CLI processing.

Mini Example

Small examples to illustrate both actions and common formats.

Encode (binary bytes): 48 65 6c 6c 6f 0a
Output (plain, lower): 48656c6c6f0a

Decode (Hex text): 48 65 6c 6c 6f 0a
Result (file bytes): 48 65 6c 6c 6f 0a
Formatting options (case, separators, wrapping, line endings) change only the Hex text representation. Decode behavior depends on the selected accept-toggles, separator handling, strict mode, and odd-length policy.

Errors & Edge Cases

Typical failures when converting between Hex text and raw bytes, and how the UI options influence them.

SymptomLikely causeWhat to check
Encode says to upload a fileYou provided text input to the encode actionThis tool encodes binary data. Switch to Decode for Hex text input, or upload a file/bytes for Encode.
Decode error: invalid hex / malformed tokensInput contains non-hex characters or a token style you disabledEnable "Accept 0x prefix" / "Accept \xHH escapes" / "Accept %HH encoding" as appropriate; decide whether to allow separators/whitespace.
Decode fails on separators or whitespaceSeparators are present but disallowed (or strict mode rejects them)Enable "Allow separators/whitespace"; if you want strict parsing, keep "Ignore non-hex characters" off and rely on explicit token acceptance.
Odd number of hex digitsTruncated hex stream or missing a nibbleSet "Odd hex digits" to "Error" to fail fast, or "Left-pad with 0" if you intentionally accept odd-length inputs.
Unexpected output size or mismatched bytesIgnoring non-hex characters removed meaningful characters, or strict mode is off and parsing is best-effortUse "Strict validation" when correctness matters; disable "Ignore non-hex characters" if you expect only well-formed tokens.
Output wrapping/newlines are not what you expect (encode)bytesPerLine, line separator, or final newline settings are enabledSet "Wrap bytes per line" to 0, choose LF vs CRLF, and toggle "Insert final newline" as needed.

Command line alternatives

For automation, CI, or sensitive data, prefer local command-line tools. The examples below are canonical and commonly available.

Linux/macOS

Encode a file to plain hex (xxd)

xxd -p -c 256 input.bin > output.hex.txt

Prints the file as plain hex (no 0x/\x tokens). Use -c to control line width.

Decode plain hex back to a file (xxd)

xxd -r -p output.hex.txt > restored.bin

Reverse plain-hex back to raw bytes. If your hex text contains separators or prefixes, normalize it first.

Node.js

Encode a file to hex (Node Buffer)

node -e "const fs=require('fs');const b=fs.readFileSync('input.bin');process.stdout.write(b.toString('hex'))" > output.hex.txt

Outputs continuous lowercase hex. Add your own formatting if you need separators or line breaks.

Decode plain hex text to a file (Node Buffer)

node -e "const fs=require('fs');const hex=fs.readFileSync('output.hex.txt','utf8').trim();fs.writeFileSync('restored.bin',Buffer.from(hex,'hex'));"

Parses only plain hex. Strip 0x/\x/% tokens and separators before decoding.

Use cases

Debugging binary payloads

  • Turn a small binary file into readable Hex for bug reports and review
  • Compare two binary outputs by converting both to a normalized Hex representation

Interoperability across tools

  • Generate 0x-prefixed or separator-delimited Hex to match the expectations of downstream tooling
  • Decode Hex dumps that include C-style \xHH tokens or percent-style %HH bytes

CI fixtures and test vectors

  • Store small binary fixtures as Hex text for easy diffs in code review
  • Use strict validation to fail fast when test inputs are malformed

Teaching bytes and representations

  • Show how the same bytes can be represented as plain hex, 0x-prefixed tokens, or \xHH escapes
  • Demonstrate why separators and odd-length handling are explicit parsing choices

❓ Frequently Asked Questions

Is there a public API?

No. This tool is designed for interactive browser use and does not expose a public API.

Is processing local or remote?

100% client-side processing (no server upload). All encoding and decoding runs locally in your browser.

Can I use this for secrets (API keys, credentials, proprietary files)?

It's safer not to. Even though processing is local, secrets can still leak via screen sharing, extensions, clipboard history, or device compromise. For sensitive data, prefer local CLI tooling.

Why does decoding fail with "invalid hex" or "malformed input"?

Most failures come from non-hex characters, disabled token acceptance (0x, \xHH, %HH), separators/whitespace handling, or an odd number of hex digits. Enable the matching "Accept" toggles, decide whether to allow separators, choose an odd-length policy, and use "Strict validation" when you want parsing to fail fast.

Pro Tips

Best Practice

For stable comparisons, encode with a fixed format (plain), a fixed case, and no separators; then add separators/wrapping only for readability.

Best Practice

When decoding dumps from code or logs, turn on the token accept options you expect (0x, \xHH, %HH) and allow separators/whitespace to avoid manual cleanup.

Security Tip

Use "Strict validation" (and consider disabling "Ignore non-hex characters") when correctness matters more than best-effort recovery.

CI Tip

Keep inputs under ~1–2MB and use local CLI tools for large files or CI pipelines to avoid browser limits/timeouts.

Additional Resources

Other Tools