Module Stdint.Uint8
Contents
Instructions: Use this module in your project
In the IDE (CLion, Visual Studio Code, Xcode, etc.) you use for your DkSDK project:
Add the following to your project's
dependencies/CMakeLists.txt:DkSDKProject_DeclareAvailable(stdint CONSTRAINT "= 0.7.2" FINDLIBS stdint) DkSDKProject_MakeAvailable(stdint)Add the
Findlib::stdintlibrary to any desired targets insrc/*/CMakeLists.txt:target_link_libraries(YourPackage_YourLibraryName # ... existing libraries, if any ... Findlib::stdint)Click your IDE's
Buildbutton
Not using DkSDK?
FIRST, do one or all of the following:
Run:
opam install stdint.0.7.2Edit your
dune-projectand add:(package (name YourExistingPackage) (depends ; ... existing dependenices ... (stdint (>= 0.7.2))))Then run:
dune build *.opam # if this fails, run: dune buildEdit your
<package>.opamfile and add:depends: [ # ... existing dependencies ... "stdint" {>= "0.7.2"} ]Then run:
opam install . --deps-only
FINALLY, add the stdint library to any desired (library)and/or (executable) targets in your **/dune files:
(library
(name YourLibrary)
; ... existing library options ...
(libraries
; ... existing libraries ...
stdint))
(executable
(name YourExecutable)
; ... existing executable options ...
(libraries
; ... existing libraries ...
stdint))typet`` =uint8
The specific integer type
Constants
valzero :t
The value 0
valone :t
The value 1
valmax_int :t
The greatest representable integer
valmin_int :t
The smallest representable integer; for unsigned integers this is
zero.
valbits : int
The number of bits used by this integer
Infix operations
Integer division. Raise Division_by_zero if the second argument is
zero. This division rounds the real quotient of its arguments towards
zero, as specified for (/).
Arithmetic operations
Integer division. Raise Division_by_zero if the second argument is
zero. This division rounds the real quotient of its arguments towards
zero, as specified for (/).
Integer remainder. If y is not zero, the result of rem x y
satisfies the following property: x = add (mul (div x y) y) (rem x y).
If y = 0, rem x y raises Division_by_zero.
Bitiwse operations
shift_left x y shifts x to the left by y bits. The result is
unspecified if y < 0 or y >= bits.
shift_right x y shifts x to the right by y bits. If this is a
signed integer, this is an arithmetic shift: the sign bit of x is
replicated and inserted in the vacated bits. The result is unspecified
if y < 0 or y >= bits. For an unsigned integer, this is identical to
shift_right_logical.
shift_right_logical x y shifts x to the right by y bits. This is a
logical shift: zeroes are inserted in the vacated bits regardless if x
is a signed or unsiged integer. The result is unspecified if y < 0 or
y >= bits.
Numeric conversion functions
valof_int : ``int->t
Convert the given integer (type int) to this integer type.
valto_int :t->int
Convert the given integer (type t) to an integer of type int.
valof_float : ``float->t
Convert the given floating-point number to an integer of type t.
valto_float :t->float
Convert the given integer to a floating-point number.
valof_nativeint : ``nativeint->t
Convert the given integer (type t) to a native integer.
valto_nativeint :t->nativeint
Convert the given native integer (type nativeint) to an integer (type
t.
String conversion functions
valof_substring : ``string->``pos:int->t* int
Convert the given substring starting at the given offset pos to an
integer of type t and return the offset. The string is read in decimal
(by default) or in hexadecimal, octal or binary if the string begins
with 0x, 0o or 0b respectively. Raise Failure "*_of_substring"
if the given string is not a valid representation of an integer, or if
the integer represented exceeds the range of integers representable in
type t.
valof_string : ``string->t
Convert the given string to an integer of type t. The string is read
in decimal (by default) or in hexadecimal, octal or binary if the string
begins with 0x, 0o or 0b respectively. Raise
Failure "*_of_string" if the given string is not a valid
representation of an integer, or if the integer represented exceeds the
range of integers representable in type t.
valto_string :t->string
Return the string representation of its argument, in decimal.
valto_string_bin :t->string
Return the string representation of its argument, in binary (beginning
with 0b)
valto_string_oct :t->string
Return the string representation of its argument, in octal (beginning
with 0o)
valto_string_hex :t->string
Return the string representation of its argument, in hex (beginning with
0x)
valprinter :Stdlib.Format.formatter->t->unit
valprinter_bin :Stdlib.Format.formatter->t->unit
valprinter_oct :Stdlib.Format.formatter->t->unit
valprinter_hex :Stdlib.Format.formatter->t->unit
Raw bytes conversion functions
valof_bytes_big_endian :Stdlib.Bytes.t->``int->t
of_bytes_big_endian buffer offset creates an integer value of type t
from the buffer buffer starting at offset offset. The byte order is
interpreted to be big endian. If the buffer does not hold enough bytes
for this integer, i.e. if
(Bytes.length buffer) < (offset + (bits / 8)), the function will raise
Invalid_argument "index out of bounds".
valof_bytes_little_endian :Stdlib.Bytes.t->``int->t
of_bytes_big_endian buffer offset creates an integer value of type t
from the buffer buffer starting at offset offset. The byte order is
interpreted to be little endian. If the buffer does not hold enough
bytes for this integer, i.e. if
(Bytes.length buffer) < (offset + (bits / 8)), the function will raise
Invalid_argument "index out of bounds".
valto_bytes_big_endian :t->Stdlib.Bytes.t->``int->unit
to_bytes_big_endian i buffer offset writes the integer i to the
buffer buffer starting at offset offset. The byte order used is big
endian. If the buffer does not hold enough bytes, i.e. if
(Bytes.length buffer) < (offset + (bits / 8)), the function will raise
Invalid_argument "index out of bounds".
valto_bytes_little_endian :t->Stdlib.Bytes.t->``int->unit
to_bytes_little_endian i buffer offset writes the integer i to the
buffer buffer starting at offset offset. The byte order used is
little endian. If the buffer does not hold enough bytes, i.e. if
(Bytes.length buffer) < (offset + (bits / 8)), the function will raise
Invalid_argument "index out of bounds".
Comparison function
The comparison function for integers of type t, with the same
specification as compare. Along with the type t, this function compare
allows this module to be passed as argument to the functors Set.Make and
Map.Make.
