Search code examples
clojure

What does Clojure’s bit-and-not do?


From the docs:

bit-and-not

function

Usage: (bit-and-not x y)
       (bit-and-not x y & more)

Bitwise and with complement

Added in Clojure version 1.0

Clojure's other bit- functions make sense to me, but I don't understand this one.


Solution

  • It is equivalent to this:

    (bit-and x (bit-not y))

    This function can be used to do subset tests. The set a (represented as a bitmask) is a subset of the set b if and only if (bit-and-not a b) is zero.