application/octet-stream
•
899 B
•
34 lines
;;; Nujel - Copyright (C) 2020-2021 - Benjamin Vincent Schulenburg
;;; This project uses the MIT license, a copy should be included under /LICENSE
;;;
;;; Some functions manipulating binary date
[defn bit-nand [a b]
"Returns the Nand of A and B"
[bit-not [bit-and a b]]]
[defn bit-and-not [x y]
"Bitwise and with complement"
[bit-and x [bit-not y]]]
[defn bit-test? [α i]
"Test bit at position i"
[typecheck/only α :int]
[typecheck/only i :int]
[not [zero? [bit-and α [bit-shift-left 1 i]]]]]
[defn bit-shift-right [α i]
"Bitwise shift right"
[bit-shift-left α [- i]]]
[defn bit-set [x i]
"Set bit at i"
[bit-or x [bit-shift-left 1 i]]]
[defn bit-flip [x i]
"Flip bit at i"
[bit-xor x [bit-shift-left 1 i]]]
[defn bit-clear [x i]
"Clear bit at i"
[bit-and x [bit-not [bit-shift-left 1 i]]]]