ktonon/elm-word/2.1.0

NOTE: this package is not compatible with Elm 0.19.1

Word.Bytes

Helper functions for creating lists of bytes.

import Word.Hex as Hex
type alias ByteCount =
Int

Total number of bytes

fromInt : ByteCount -> Int -> List Int

Split an integer value into a list of bytes with the given length.

fromInt 4 0 |> Hex.fromByteList
--> "00000000"


fromInt 4 1 |> Hex.fromByteList
--> "00000001"


fromInt 2 2 |> Hex.fromByteList
--> "0002"


fromInt 1 255 |> Hex.fromByteList
--> "ff"


fromInt 4 256 |> Hex.fromByteList
--> "00000100"


fromInt 4 65537 |> Hex.fromByteList
--> "00010001"


fromInt 4 16777216 |> Hex.fromByteList
--> "01000000"


fromInt 8 344 |> Hex.fromByteList
--> "0000000000000158"


fromInt 16 344 |> Hex.fromByteList
--> "00000000000000000000000000000158"
fromUTF8 : String -> List Int

Convert a character into a list of bytes

fromUTF8 "a" |> Hex.fromByteList
--> "61"


fromUTF8 "I ❤ cheese"
--> [ 73, 32,
-->   226, 157, 164,
-->   32, 99, 104, 101, 101, 115, 101 ]


fromUTF8 "dѐf"
--> [ 100, 209, 144, 102 ]