Hexadecimal encoding and decoding functions.
Functions
decode core
fn (hex-str: Str): Bytes
Decode hexadecimal string to bytes.
Example
decode("48656c6c6f")
// Bytes([72, 101, 108, 108, 111]) — the bytes for "Hello"
// Convert decoded bytes to string
Str(decode("48656c6c6f"))
// "Hello"
encode core
fn (data: Str | Bytes): Str
Encode bytes or string to hexadecimal string.
Example
encode("Hello")
// "48656c6c6f"
encode(Bytes([72, 101, 108, 108, 111]))
// "48656c6c6f"
is-valid
fn (s: Str): Bool
Check if a string is valid hexadecimal (even length, valid hex characters).
Example
is-valid("48656c6c6f") // true
is-valid("48656c6c6") // false (odd length)
is-valid("ghijkl") // false (invalid chars)