oboy/src/bit.ml

13 lines
241 B
OCaml
Raw Normal View History

let is_set num i =
2015-04-19 19:18:20 +02:00
if i < 0 then
failwith "Invalid bit index."
else
(num lsr i) land 0b00000001 <> 0
2015-08-11 22:49:27 +02:00
let two_complement n =
(lnot n) + 1
let signed_byte n =
if n land 0x80 <> 0 then -((two_complement n) land 0xFF)
else n