Login
7 branches 0 tags
Ben (X220/Parabola) Added support for literals to BCArrays 0f4741a 3 years ago 672 Commits
nujel / stdlib / bitmanip.nuj
;; 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 lognand l
      "Returns the Nand of its arguments"
      [lognot [apply logand l]]]

[defn bit-set? [α i]
      "Returns #t if bit I is set in Α"
      [typecheck/only α :int]
      [typecheck/only i :int]
      [not [zero? [logand α [ash 1 i]]]]]

[defn bit-set?! [i]
      "Returns a function that checks if bit I is set in the provided number"
      [typecheck/only i :int]
      [def mask [ash 1 i]]
      [fn [α]
          [not [zero? [logand α mask]]]]]

[defn bit-clear?! [i]
      "Returns a function that checks if bit I is clear in the provided number"
      [typecheck/only i :int]
      [def mask [ash 1 i]]
      [fn [α]
          [zero? [logand α mask]]]]

[defn test-function [i]
      "Returns a function that checks if bit I is clear in the provided number"
      [def mask [ash 1 i]]
      [fn [α]
          [zero? [logand α mask]]]]