Working with an Arr of Bits. To import as Bits
Convert an Arr of up to 53 Bits to a Nat.
Bits from the 53th index become mathematically unsound so they are avoided.
Bits.toNat (Arr.from8 I O O O I O I O)
--> Nat 138Group an Arr of Bits into Arrs of size 8.
Bits.toBytes (Arr.from1 O)
--> Arr.from1 (Arr.from8 O O O O O O O O)
Arr.from3 I I I
|> Arr.extend nat8 (Arr.from8 O I I I O I O O)
|> Arr.extend nat8 (Arr.from8 O I I I O I O O)
|> Arr.extend nat8 (Arr.from8 O I I I O I O O)
|> Bits.toBytes
--> (Arr.from8 O O O O O I I I
--> |> Arr.push (Arr.from8 O I I I O I O O)
--> |> Arr.push (Arr.from8 O I I I O I O O)
--> |> Arr.push (Arr.from8 O I I I O I O O)
--> )Os at the start are kept.
Fill Os to the begin of the Arr until it has 8 elements.
Arr.from3 I I I |> Bits.padToByte
--> Arr.from8 O O O O O I I IA Codec for an Arr of Bits.
To get a Codec with a string error:
import Serialize exposing (Codec)
bit128 :
Codec
String
(Arr (In Nat128 (Nat128Plus a_)) Bit)
bit128 =
Bits.serialize nat128
Arr.serializeErrorToString
Lue. is just the github username to avoid overlaps in module names.
A
Random.Generatorfor anArrofBits.To use it effectively, you will need some extra bits of randomness.