Library
Module
Module type
Parameter
Class
Class type
Z Convert Z to big endian Cstruct.t and generate random Z values.
of_cstruct_be ~bits cs
interprets the bit pattern of cs
as a t
in big-endian.
If ~bits
is not given, the operation considers the entire cs
, otherwise the initial min ~bits (bit-length cs)
bits of cs
.
Assuming n
is the number of bits to extract, the n
-bit in cs
is always the least significant bit of the result. Therefore:
k
of t
is larger than n
, k - n
most significant bits in the result are 0
; andk
is smaller than n
, the result contains k
last of the n
first bits of cs
.val to_cstruct_be : ?size:int -> Z.t -> Cstruct.t
to_cstruct_be ~size t
is the big-endian representation of t
.
If ~size
is not given, it defaults to the minimal number of bytes needed to represent t
, which is bits t / 8
rounded up.
The least-significant bit of t
is always the last bit in the result. If the size is larger than needed, the output is padded with zero bits. If it is smaller, the high bits in t
are dropped.
val into_cstruct_be : Z.t -> Cstruct.t -> unit
into_cstruct_be t cs
writes the big-endian representation of t
into cs
. It behaves like to_cstruct_be
, with ~size
spanning the entire cs
.
gen ~g n
picks a value in the interval [0, n - 1]
uniformly at random.