The Hex.Convert package converts Bytes values to and from String
values. Three functions are exposed:
toString : Bytes -> StringtoBytes : String -> Maybe Bytesblocks : Int -> String -> List StringThe toString function converts a Bytes value to
a string of hexadecimal characters representing the Bytes value.
The toBytes function converts a string to a value of type Maybe Bytes.
This choice of return type is necessary to account for the fact
that a function call can fail, e.g., on the input "6A45F!".
The blocks function is used to "format" the output
of toString into blocks of a given number of characters.
Do import Bytes.Encode as Encode exposing(encode). Then
encode (Encode.string "Hello")
|> Hex.Convert.toString
--> "48656C6C6F" : String
Hex.Convert.toBytes "FF66!!"
|> Maybe.map Hex.Convert.toString
--> Nothing : Maybe StringThe blocks function is a general-purpose
string utility which divides a string into blocks
of characters, that is, a list of strings:
"abcdefhij" |> Hex.Convert.blocks 3
--> ["abc","def","hij"]