# Hex

> Text to UTF-8 bytes in hex and back: plain, spaced, \x, or 0x.

Category: Encoding · Page: https://util.caruana.me/tools/hex/

## API, MCP and A2A

### Hex: Text → Hex (`hex_encode`)

`GET|POST https://util.caruana.me/api/hex/encode` · MCP tool `hex_encode` · A2A skill `hex_encode` · [reference](https://util.caruana.me/reference/hex_encode/)

Writes each UTF-8 byte of `input` as two lowercase hex digits in the chosen layout.

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `input` | string | yes | Text to convert. As a `text/plain` POST body it is used verbatim. |
| `mode` | plain \| spaced \| escaped \| prefixed | no | `plain`: 48656c6c6f — contiguous lowercase hex. `spaced`: 48 65 6c 6c 6f — one byte per pair. `escaped`: \x48\x65\x6c — C, Python, and shell string escapes. `prefixed`: 0x48, 0x65, 0x6c — array-literal style |

Privacy: The server receives the `input` text and `mode`, converts it in memory inside the request, and returns the result. Your input is not stored or logged; only the per-call metadata row (operation, time, status, sizes) is recorded. Send secrets in a POST body, not the query string: URLs are recorded in Cloudflare request logs, proxies, and shell history.

### Hex: Hex → Text (`hex_decode`)

`GET|POST https://util.caruana.me/api/hex/decode` · MCP tool `hex_decode` · A2A skill `hex_decode` · [reference](https://util.caruana.me/reference/hex_decode/)

Accepts any mix of plain, spaced, `\x`, `0x`, comma, and colon separated hex, in either case.

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `input` | string | yes | Text to convert. As a `text/plain` POST body it is used verbatim. |
| `mode` | plain \| spaced \| escaped \| prefixed | no | `plain`: 48656c6c6f — contiguous lowercase hex. `spaced`: 48 65 6c 6c 6f — one byte per pair. `escaped`: \x48\x65\x6c — C, Python, and shell string escapes. `prefixed`: 0x48, 0x65, 0x6c — array-literal style |

Privacy: The server receives the `input` text and `mode`, converts it in memory inside the request, and returns the result. Your input is not stored or logged; only the per-call metadata row (operation, time, status, sizes) is recorded. Send secrets in a POST body, not the query string: URLs are recorded in Cloudflare request logs, proxies, and shell history.


## User guide

The tool sits in a window that works like a desktop app: menus on the top row and the **full-screen** icon at its right (**Esc** leaves full screen). The set-up options described below are in **Settings → Options…**, an overlay, and the **Settings** menu also lists the common choices directly. To keep the options in view instead, choose **View → Inline config**; the page remembers that choice. **Help → Keyboard shortcuts…** lists the keys.

1. **Text → Hex** shows the UTF-8 bytes of your text. Choose a layout:
   - **Plain:** `486920e282ac`
   - **Spaced:** `48 69 20 e2 82 ac`
   - **`\x`:** `\x48\x69…`, for C, Python and shell strings
   - **`0x`:** `0x48, 0x69, …`, for array literals
2. **Hex → Text** accepts any of those layouts, mixed, in upper or lower case. Colons are allowed too (`48:69`).

This is a quick way to see why a "simple" string is longer than expected: `€` is three bytes (`e2 82 ac`) in UTF-8.

## Specification

- **Encoding.** Each UTF-8 byte of the input becomes two lowercase hex digits.

| Mode       | Separator and prefix                      |
| ---------- | ----------------------------------------- |
| `plain`    | none                                      |
| `spaced`   | one space between bytes                   |
| `escaped`  | `\x` before each byte, no separator       |
| `prefixed` | `0x` before each byte, `, ` between bytes |

- **Decoding.**
  1. Remove every `0x` and `\x` prefix (case-insensitive), plus whitespace, commas and colons.
  2. What remains must be an even number of hex digits.
  3. The resulting bytes must be valid UTF-8; decoding uses fatal mode, so nothing is silently replaced.
- **Errors.** Odd digit count, a non-hex character, or invalid UTF-8 (meaning binary data, which this tool does not display).
