Bitwise logical `and' of zero or more integers
When integers are viewed in their two's complement representation,
The guard for
Macro:
(defmacro logand (&rest args) (cond ((null args) -1) ((null (cdr args)) (cons 'the (cons 'integer (cons (car args) 'nil)))) (t (xxxjoin 'binary-logand args))))
Function:
(defun binary-logand (i j) (declare (xargs :guard (and (integerp i) (integerp j)))) (cond ((zip i) 0) ((zip j) 0) ((eql i -1) j) ((eql j -1) i) (t (let ((x (* 2 (logand (floor i 2) (floor j 2))))) (+ x (cond ((evenp i) 0) ((evenp j) 0) (t 1)))))))