package frenetic

  1. Overview
  2. Docs
The Frenetic Programming Language and Runtime System

Install

Dune Dependency

Authors

Maintainers

Sources

5.0.5.tar.gz
md5=baf754df13a759c32f2c86a1b6f328da
sha512=80140900e7009ccab14b25e244fe7edab87d858676f8a4b3799b4fea16825013cf68363fe5faec71dd54ba825bb4ea2f812c2c666390948ab217ffa75d9cbd29

doc/src/frenetic.kernel/Bits.ml.html

Source file Bits.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
let clear_bit (n:int) (x:int32) : int32 =
  Int32.logand x (Int32.lognot (Int32.shift_left Int32.one n))

let set_bit (n:int) (x:int32) : int32 =
  Int32.logor x (Int32.shift_left Int32.one n)

let bit (x : int32) (n : int) (v : bool) : int32 =
  if v then set_bit n x else clear_bit n x

let test_bit (n:int) (x:int32) : bool =
  Int32.logand (Int32.shift_right_logical x n) Int32.one = Int32.one

let get_byte32 (n : Int32.t) (i : int) : int = 
  let open Int32 in
  if i < 0 || i > 3 then
    raise (Invalid_argument "get_byte32 index out of range");
  to_int (logand 0xFFl (shift_right_logical n (8 * i)))

let get_byte (n:int64) (i:int) : int =
  if i < 0 || i > 7 then
    raise (Invalid_argument "Int64.get_byte index out of range");
  Int64.to_int (Int64.logand 0xFFL (Int64.shift_right_logical n (8 * i)))
OCaml

Innovation. Community. Security.