Implemention of base 16 encoding (hex encoding) as specified in RFC 4648 (http://tools.ietf.org/html/rfc4648).
This function, unlike some other encoding functions in the library, simply cannot fail. Double the length of the input string is allocated for the encoded data, which is guaranteed to hold the result.
b16_enc $ Data.ByteString.pack [0x00]"00"
b16_enc $ Data.ByteString.Char8.pack "foobar""666F6F626172"
The returned value on success is
Right <decoded string>, and on failure
Left (<decoded part>, <undecodable part>). Space equal to the
length of the input string is allocated, which is more than enough to hold
the decoded data.
b16_dec $ Data.ByteString.Char8.pack "00"Right "\NUL"
b16_dec $ Data.ByteString.Char8.pack "666F6F626172"Right "foobar"
b16_dec $ Data.ByteString.Char8.pack "666F6F62617"Left ("fooba","7")