Codec lesson · Base16 / Hex

Base16 / Hex: read every UTF-8 byte directly

Base16, commonly called hexadecimal or Hex, writes every byte as two symbols from 0–9 and A–F. It is direct and readable when inspecting bytes.

Standard · RFC 4648 Round trip: Exact for complete Base16 byte pairs that decode to valid UTF-8 text.
Learning objective

Connect one byte to two hexadecimal digits and identify incomplete pairs or byte sequences that are not valid UTF-8 text.

Encode Keyboard writes canonical uppercase Base16 with no separators. Decode accepts upper- or lowercase hex and ASCII whitespace, then requires complete byte pairs and valid UTF-8.

01

How Encode Keyboard handles it

1

Create UTF-8 bytes

Each input character becomes one or more bytes under UTF-8.

2

Split each byte in half

The high and low four-bit values each map to one hexadecimal digit.

3

Validate byte pairs

Decode rejects non-hex symbols, odd digit counts, and bytes that do not form valid UTF-8 text. An initial U+FEFF is preserved.

02

Worked example

InputHi
Output4869

H is byte 0x48 and i is byte 0x69, so each input byte occupies exactly two hex digits.

03

Good uses

  • Inspecting UTF-8 bytes compactly
  • Comparing text with byte-level logs
  • Learning how binary nibbles map to hexadecimal
04

Validation and common errors

  • Use only digits 0–9 and letters A–F or a–f
  • Provide an even number of digits after optional whitespace is removed
  • Remember that valid byte pairs may still be invalid UTF-8 text
05

Practice in your browser

This uses the same documented rules as the app and runs only in this tab.

Base16 / HexThis uses the same documented rules as the app and runs only in this tab.
Result

This uses the same documented rules as the app and runs only in this tab.

06

Knowledge check

Why does each byte always need two Base16 digits?