application/octet-stream
•
949 B
•
36 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 l
"Returns the Nand of its arguments"
[bit-not [apply bit-and l]]]
[def lognand bit-nand]
[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]]]]]
[def bit-set? bit-test?]
[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]]]]