Encodings

Hex

Base16 from RFC 4648. Two digits per byte and either case and a 0x prefix on decode
IDhex02 / 20hex · 16 characters
Encoding / Hex

Hex (Base16)

Two digits a byte. The one everybody reads.

Overhead
+100% on random bytes
Padding
none
Standard
RFC 4648 §8
Family
1 in hex
family 1 / 20

Sample

Out
68656c6c6f20776f726c6421
Back
"hello world!"

Options

upperboolean
default false
Write A-F instead of a-f

Access

Importimport { hex } from "@agntn/encodings/hex"
CLIencodings encode hex 'hello world!'
Tryplayground with the sample above

Two digits a byte. The encoding everybody already reads without thinking.

ts
encode("hex", "gm");                   // "676d"
encode("hex", "gm", { upper: true });  // "676D"
decode("hex", "0x67 6D").bytes;        // Uint8Array [103, 109]

Decoding takes either case. It drops one leading 0x and skips spaces and line breaks. So a hex dump pastes straight in. An odd number of digits? Error. Half a byte isn't a byte.