jxxcarlson/hex/2.0.1

NOTE: the latest version is 4.0.1

Hex

The Hex package exposes two functions

  • fromBytes : Bytes -> String
  • toBytes : String -> Maybe Bytes

The first gives a hexadecimal representation of a Bytes, value, e.g., something like "6A45F2". The second takes a string like the one just given and returns a value of type Maybe Bytes. Such a function call can fail, e.g., on an input "6A45F!".

fromBytes : Bytes -> String

Hex.toBytes "FF66" |> Maybe.map Hex.fromBytes == Just "FF66"

import Bytes.Encode as Encode exposing(encode) encode (Encode.string "Hello") |> Hex.fromBytes "48656C6C6F" : String

Hex.toBytes "FF66!!" |> Maybe.map Hex.fromBytes Nothing : Maybe String

toBytes : String -> Maybe Bytes

Hex.toBytes "FF66" |> Maybe.map Hex.fromBytes == Just "FF66"