21 lines
455 B
OCaml
21 lines
455 B
OCaml
|
(**
|
||
|
* Copyright (c) 2015, Fabien Freling
|
||
|
* All rights reserved.
|
||
|
*
|
||
|
* This source code is licensed under the BSD 2-clause license found in the
|
||
|
* LICENSE file at the top level directory of this source tree.
|
||
|
*)
|
||
|
|
||
|
let is_set num i =
|
||
|
if i < 0 then
|
||
|
failwith "Invalid bit index."
|
||
|
else
|
||
|
(num lsr i) land 0b00000001 <> 0
|
||
|
|
||
|
let two_complement n =
|
||
|
(lnot n) + 1
|
||
|
|
||
|
let signed_byte n =
|
||
|
if n land 0x80 <> 0 then -((two_complement n) land 0xFF)
|
||
|
else n
|