elm-cardano/x-bytes/1.0.0

NOTE: the latest version is 1.1.0

Hex

Convert between Bytes and hexadecimal strings.

  • fromBytes encodes Bytes into a lowercase hex String.
  • toBytes decodes a hex String (mixed-case) into Bytes, with validation.
  • toBytesUnchecked decodes a lowercase hex String into Bytes, without validation.
fromBytes : Bytes -> String

Convert Bytes to a lowercase hex string.

import Bytes.Encode as Encode


Encode.encode (Encode.unsignedInt8 255)
    |> fromBytes
--> "ff"
toBytes : String -> Maybe Bytes

Parse a hex string into Bytes. Returns Nothing if the string has odd length or contains non-hex characters. Accepts both uppercase and lowercase hex digits.

toBytes "ff"
--> Just <1 byte>


toBytes "zz"
--> Nothing
toBytesUnchecked : String -> Bytes

Parse a lowercase hex string into Bytes. Does not validate the input: assumes even length and only lowercase hex characters (0-9, a-f). About 20% faster than toBytes.

toBytesUnchecked "ff"
--> <1 byte>