
ANSI Common Lisp 12 Numbers 12.2 Dictionary of Numbers
12.2.62 logand, logandc1, logandc2, logeqv, logior, lognand, lognor, lognot, logorc1, logorc2, logxor 
Function 
 Syntax:

logand
&rest integers
resultinteger
logandc1
integer1 integer2
resultinteger
logandc2
integer1 integer2
resultinteger
logeqv
&rest integers
resultinteger
logior
&rest integers
resultinteger
lognand
integer1 integer2
resultinteger
lognor
integer1 integer2
resultinteger
lognot
integer
resultinteger
logorc1
integer1 integer2
resultinteger
logorc2
integer1 integer2
resultinteger
logxor
&rest integers
resultinteger
 Arguments and Values:

integers  integers.
integer  an integer.
integer1  an integer.
integer2  an integer.
resultinteger  an integer.
 Description:

The functions
logandc1,
logandc2,
logand,
logeqv,
logior,
lognand,
lognor,
lognot,
logorc1,
logorc2,
and logxor
perform bitwise logical operations on their arguments,
that are treated as if they were binary.
The next figure lists the meaning of each of the functions.
Where an `identity' is shown, it indicates the value yielded
by the function when no arguments are supplied.
Bitwise Logical Operations on Integers
Function 
Identity 
Operation performed 
logandc1 
 
and complement of integer1 with integer2 
logandc2 
 
and integer1 with complement of integer2 
logand 
1 
and 
logeqv 
1 
equivalence (exclusive nor) 
logior 
0 
inclusive or 
lognand 
 
complement of integer1 and integer2 
lognor 
 
complement of integer1 or integer2 
lognot 
 
complement 
logorc1 
 
or complement of integer1 with integer2 
logorc2 
 
or integer1 with complement of integer2 
logxor 
0 
exclusive or 
Negative integers are treated as if they were in two'scomplement notation.
 Examples:

(logior 1 2 4 8) 15
(logxor 1 3 7 15) 10
(logeqv) 1
(logand 16 31) 16
(lognot 0) 1
(lognot 1) 2
(lognot 1) 0
(lognot (1+ (lognot 1000))) 999
;;; In the following example, m is a mask. For each bit in
;;; the mask that is a 1, the corresponding bits in x and y are
;;; exchanged. For each bit in the mask that is a 0, the
;;; corresponding bits of x and y are left unchanged.
(flet ((show (m x y)
(format t "~%m = #o~6,'0O~%x = #o~6,'0O~%y = #o~6,'0O~%"
m x y)))
(let ((m #o007750)
(x #o452576)
(y #o317407))
(show m x y)
(let ((z (logand (logxor x y) m)))
(setq x (logxor z x))
(setq y (logxor z y))
(show m x y))))
m = #o007750
x = #o452576
y = #o317407
m = #o007750
x = #o457426
y = #o312557
NIL
 Exceptional Situations:

Should signal typeerror if any argument is not an integer.
 See Also:

boole
 Notes:

(logbitp k 1) returns true for all values of k.
Because the following functions are not associative,
they take exactly two arguments rather than any number
of arguments.
(lognand n1 n2) ==(lognot (logand n1 n2))
(lognor n1 n2) ==(lognot (logior n1 n2))
(logandc1 n1 n2) ==(logand (lognot n1) n2)
(logandc2 n1 n2) ==(logand n1 (lognot n2))
(logiorc1 n1 n2) ==(logior (lognot n1) n2)
(logiorc2 n1 n2) ==(logior n1 (lognot n2))
(logbitp j (lognot x)) ==(not (logbitp j x))
 Allegro CL Implementation Details:

None.
