Unsigned 32 or 64 bit integers and related operations.
Use the Word type to hold either 32 or 64 bit unsigned integers. Use the exposed type constructors W (for "word") and D (for "double word") to store values as words.
import Word exposing (Word(D, W))The following operations are provided.
add - modulo additionand - bitwise andxor - bitwise xorcomplement - bitwise inversionrotateRightBy - rotate rightshiftRightZfBy - logical shift rightNote that the set of operations is the minimal required to implement SHA-2.
Addition of words is modulo 32 bits.
add (W 0x80000000)
(W 0x80000003)
--> W 3Addition of double words is modulo 64 bits.
add (D 0 0xFFFFFFFF)
(D 0 1)
--> D 1 0Double words are stored as two 32 bit values because Elm makes arithmetic mistakes with larger values. For example, try typing this into the elm repl:
$ elm repl
---- elm-repl 0.18.0 -----------------------------------------------------------
> 2 ^ 60 + 55 == 2 ^ 60
True : Boolgilbertkennen/bigint: Work with integers of unlimited size.
mthadley/elm-byte: A library for working with 8-bit unsigned integers with type safety.