Encodings
Hex
Base16 from RFC 4648. Two digits per byte and either case and a 0x prefix on decode
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!"
0123456789abcdef
Options
Access
- Import
import { hex } from "@agntn/encodings/hex" - CLI
encodings encode hex 'hello world!' - Tryplayground with the sample above
Two digits a byte. The encoding everybody already reads without thinking.
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.