Library
Module
Module type
Parameter
Class
Class type
Z Convert Z to big endian string and generate random Z values.
val of_octets_be : ?bits:int -> string -> Z.t
of_octets_be ~bits buf
interprets the bit pattern of buf
as a t
in big-endian.
If ~bits
is not given, the operation considers the entire buf
, otherwise the initial min ~bits (bit-length buf)
bits of buf
.
Assuming n
is the number of bits to extract, the n
-bit in buf
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 buf
.val to_octets_be : ?size:int -> Z.t -> string
to_octets_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_octets_be : Z.t -> bytes -> unit
into_octets_be t buf
writes the big-endian representation of t
into buf
. It behaves like to_octets_be
, with ~size
spanning the entire buf
.
gen ~g n
picks a value in the interval [0, n - 1]
uniformly at random.