#hex
Hexadecimal encoding and decoding.
encode/decode take and return Bytes. Each byte becomes two hex
digits, most significant first. Encoding produces lowercase digits and
decoding accepts either case; encodeUpper produces uppercase digits.
#Encoding
#encode
encode : Bytes -> String
encode bThe bytes as lowercase hex, two digits per byte.
> encode (fromU8Array [|255, 0, 16|])
"ff0010"#encodeUpper
encodeUpper : Bytes -> String
encodeUpper bThe bytes as uppercase hex, two digits per byte.
> encodeUpper (fromU8Array [|255, 0, 16|])
"FF0010"#encodeString
encodeString : String -> String
encodeString sThe UTF-8 bytes of a string as lowercase hex.
> encodeString "Hello"
"48656c6c6f"#Decoding
#decode
decode : String -> Result String Bytes
decode sThe bytes written in a hex string, as a Bytes.
Err when the string has an odd length or any character that is not a
hex digit. Whitespace is not skipped.
> map toArray (decode "ff0010")
Ok [|255, 0, 16|]
> decode "zz"
Err "hex.decode: invalid hex digit"#decodeString
decodeString : String -> Result String String
decodeString sThe string whose UTF-8 bytes are written in a hex string.
> decodeString "48656c6c6f"
Ok "Hello"