User Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

cl:functions:logand [2019/07/14 17:00]
cl:functions:logand [2019/09/18 01:00] (current)
Line 1: Line 1:
 +====== Function LOGAND, LOGANDC1, LOGANDC2, LOGEQV, LOGIOR, LOGNAND, LOGNOR, LOGNOT, LOGORC1, LOGORC2, LOGXOR ======
 +
 +====Syntax====
 +
 +**logand** //''&​rest''​ integers// → //​result-integer// ​
 +**logandc1** //integer-1 integer-2// → //​result-integer// ​
 +**logandc2** //integer-1 integer-2// → //​result-integer// ​
 +**logeqv** //''&​rest''​ integers// → //​result-integer// ​
 +**logior** //''&​rest''​ integers// → //​result-integer// ​
 +**lognand ** //integer-1 integer-2// → //​result-integer// ​
 +**lognor ** //integer-1 integer-2// → //​result-integer// ​
 +**lognot** //integer// → //​result-integer// ​
 +**logorc1 ** //integer-1 integer-2// → //​result-integer// ​
 +**logorc2 ** //integer-1 integer-2// → //​result-integer// ​
 +**logxor** //''&​rest''​ integers// → //​result-integer//​
 +
 +====Arguments and Values====
 +  * //​integers//​ - //​[[CL:​Glossary:​integer|integers]]//​.
 +  * //integer// - an //​[[CL:​Glossary:​integer]]//​.
 +  * //​integer-1//​ - an //​[[CL:​Glossary:​integer]]//​.
 +  * //​integer-2//​ - an //​[[CL:​Glossary:​integer]]//​.
 +  * //​result-integer//​ - an //​[[CL:​Glossary:​integer]]//​.
 +
 +====Description====
 +
 +The //​[[CL:​Glossary:​functions]]//​ **logandc1**,​ **[[CL:​Functions:​logandc2**,​ **logand**, **logeqv**, **logior**, **lognand**,​ **lognor**, **lognot**, **logorc1**,​ **logorc2**,​ and **logxor** perform bit-wise logical operations on their //​[[CL:​Glossary:​arguments]]//,​ that are treated as if they were binary.
 +
 +The table below lists the meaning of each of the //​[[CL:​Glossary:​functions]]//​. Where an `identity'​ is shown, it indicates the //​[[CL:​Glossary:​value]]//​ //​[[CL:​Glossary:​yielded]]//​ by the //​[[CL:​Glossary:​function]]//​ when no //​[[CL:​Glossary:​arguments]]//​ are supplied.
 +
 +^ Function ​    ^ Identity ^ Operation performed ​                               ^
 +| **logandc1** | ---      | and complement of //​integer-1//​ with //​integer-2//​ |
 +| **logandc2** | ---      | and //​integer-1//​ with complement of //​integer-2//​ |
 +| **logand** ​  | ''​-1'' ​  | and                                                |
 +| **logeqv** ​  | ''​-1'' ​  | equivalence (exclusive nor)                        |
 +| **logior** ​  | ''​0'' ​   | inclusive or                                       |
 +| **lognand** ​ | ---      | complement of //​integer-1//​ and //​integer-2// ​     |
 +| **lognor** ​  | ---      | complement of //​integer-1//​ or //​integer-2// ​      |
 +| **lognot** ​  | ---      | complement ​                                        |
 +| **logorc1** ​ | ---      | or complement of //​integer-1//​ with //​integer-2// ​ |
 +| **logorc2** ​ | ---      | or //​integer-1//​ with complement of //​integer-2// ​ |
 +| **logxor** ​  | ''​0'' ​   | exclusive or                                       |
 +
 +Negative //​integers//​ are treated as if they were in two'​s-complement notation.
 +
 +====Examples====
 +
 +<​blockquote>​
 +(logior 1 2 4 8) <r>15 </r>
 +(logxor 1 3 7 15) <r>10 </r>
 +(logeqv) <r>-1 </r>
 +(logand 16 31) <r>16 </r>
 +(lognot 0) <r>-1 </r>
 +(lognot 1) <r>-2 </r>
 +(lognot -1) <r>0 </r>
 +(lognot ([[CL:​Functions:​math-one-plus|1+]] (lognot 1000))) <​r>​999</​r>​
 +</​blockquote>​
 +
 +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. ​
 +
 +<​blockquote>​
 +([[CL:​Special Operators:​flet]] ((show (m x y) 
 +         ​([[CL:​Functions:​format]] [[CL:​Constant Variables:​t]] "~%m = #​o~6,'​0O~%x = #​o~6,'​0O~%y = #​o~6,'​0O~%"​
 +                 m x y))) 
 +  ([[CL:​Special Operators:​let]] ((m #​o007750) ​
 +        (x #​o452576) ​
 +        (y #​o317407)) ​
 +    (show m x y) 
 +    ([[CL:​Special Operators:​let]] ((z (logand (logxor x y) m))) 
 +      ([[CL:​Macros:​setf]] x (logxor z x)) 
 +      ([[CL:​Macros:​setf]] y (logxor z y)) 
 +      (show m x y))))
 +<o>m = #o007750
 +x = #o452576
 +y = #o317407
 +
 +m = #o007750
 +x = #o457426
 +y = #o312557 </o>
 +<​r>​NIL </r>
 +</​blockquote>​
 +
 +====Side Effects====
 +None.
 +
 +====Affected By====
 +None.
 +
 +====Exceptional Situations====
 +Should signal **[[CL:​Types:​type-error]]** if any argument is not an //​[[CL:​Glossary:​integer]]//​.
 +
 +====See Also====
 +  * **[[CL:​Functions:​boole|Function BOOLE]]**
 +
 +====Notes====
 +''​(logbitp //k// -1)''​ returns //​[[CL:​Glossary:​true]]//​ for all values of //k//.
 +
 +Because the following functions are not associative,​ they take exactly two arguments rather than any number of arguments.
 +
 +<​blockquote> ​
 +(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//)) ≡ ([[CL:​Functions:​not]] (logbitp //j// //​x//​)) ​
 +</​blockquote>​
 +