User Tools

A PCRE internal error occured. This might be caused by a faulty plugin

====== Function BOOLE ====== ====Syntax==== * **boole** //op integer-1 integer-2// → //result-integer// ====Arguments and Values==== * //op// - a //[[CL:Glossary:bit-wise logical operation specifier]]//. * //integer-1// - an //[[CL:Glossary:integer]]//. * //integer-2// - an //[[CL:Glossary:integer]]//. * //result-integer// - an //[[CL:Glossary:integer]]//. ====Description==== **boole** performs bit-wise logical operations on //integer-1// and //integer-2//, which are treated as if they were binary and in two's complement representation. The operation to be performed and the return value are determined by //op//. **boole** returns the values specified for any //op// in the following table. ^ Op ^ Result ^ | **[[CL:Variables:boole-1]]** | //integer-1// | | **[[CL:Variables:boole-2]]** | //integer-2// | | **[[CL:Variables:boole-andc1]]** | and complement of //integer-1// with //integer-2// | | **[[CL:Variables:boole-andc2]]** | and //integer-1// with complement of //integer-2// | | **[[CL:Variables:boole-and]]** | and | | **[[CL:Variables:boole-c1]]** | complement of //integer-1// | | **[[CL:Variables:boole-c2]]** | complement of //integer-2// | | **[[CL:Variables:boole-clr]]** | always 0 (all zero bits) | | **[[CL:Variables:boole-eqv]]** | equivalence (exclusive nor) | | **[[CL:Variables:boole-ior]]** | inclusive or | | **[[CL:Variables:boole-nand]]** | not-and | | **[[CL:Variables:boole-nor]]** | not-or | | **[[CL:Variables:boole-orc1]]** | or complement of //integer-1// with //integer-2// | | **[[CL:Variables:boole-orc2]]** | or //integer-1// with complement of //integer-2// | | **[[CL:Variables:boole-set]]** | always -1 (all one bits) | | **[[CL:Variables:boole-xor]]** | exclusive or | ====Examples==== <blockquote> (boole boole-ior 1 16) <r>17 </r> (boole boole-and -2 5) <r>4 </r> (boole boole-eqv 17 15) <r>-31</r> </blockquote> The below examples illustrate the result of applying BOOLE and each of the possible values of OP to each possible combination of bits. <blockquote> ([[CL:Special Operators:progn]] ([[CL:Functions:format]] [[CL:Constant Variables:t]] "~&Results of (BOOLE <op> #b0011 #b0101) ...~ ~%---Op-------Decimal-----Binary----Bits---~%") ([[CL:Macros:dolist]] (symbol '([[CL:Constant Variables:boole-1]] [[CL:Constant Variables:boole-2]] [[CL:Constant Variables:boole-and]] [[CL:Constant Variables:boole-andc1]] [[CL:Constant Variables:boole-andc2]] [[CL:Constant Variables:boole-c1]] [[CL:Constant Variables:boole-c2]] [[CL:Constant Variables:boole-clr ]] [[CL:Constant Variables:boole-eqv]] [[CL:Constant Variables:boole-ior]] [[CL:Constant Variables:boole-nand]] [[CL:Constant Variables:boole-nor]] [[CL:Constant Variables:boole-orc1]] [[CL:Constant Variables:boole-orc2]] [[CL:Constant Variables:boole-set]] [[CL:Constant Variables:boole-xor]])) ([[CL:Special Operators:let]] ((result (boole ([[CL:Functions:symbol-value]] symbol) #b0011 #b0101))) ([[CL:Functions:format]] [[CL:Constant Variables:t]] "~& ~A~13T~3,' D~23T~:*~5,' B~31T ...~4,'0B~%" symbol result ([[CL:Functions:logand]] result #b1111))))) <o>Results of (BOOLE <op> #b0011 #b0101) ... ---Op-------Decimal-----Binary----Bits--- BOOLE-1 3 11 ...0011 BOOLE-2 5 101 ...0101 BOOLE-AND 1 1 ...0001 BOOLE-ANDC1 4 100 ...0100 BOOLE-ANDC2 2 10 ...0010 BOOLE-C1 -4 -100 ...1100 BOOLE-C2 -6 -110 ...1010 BOOLE-CLR 0 0 ...0000 BOOLE-EQV -7 -111 ...1001 BOOLE-IOR 7 111 ...0111 BOOLE-NAND -2 -10 ...1110 BOOLE-NOR -8 -1000 ...1000 BOOLE-ORC1 -3 -11 ...1101 BOOLE-ORC2 -5 -101 ...1011 BOOLE-SET -1 -1 ...1111 BOOLE-XOR 6 110 ...0110</o> <r>[[CL:Constant Variables:nil|NIL]]</r> </blockquote> ====Affected By==== None. ====Exceptional Situations==== Should signal **[[CL:Types:type-error]]** if its first argument is not a //[[CL:Glossary:bit-wise logical operation specifier]]// or if any subsequent argument is not an //[[CL:Glossary:integer]]//. ====See Also==== * **[[CL:Functions:logand|Function LOGAND]]** ====Notes==== In general: <blockquote> (boole boole-and x y) ≡ (logand x y) </blockquote> //[[CL:Glossary:Programmers]]// who would prefer to use numeric indices rather than //[[CL:Glossary:bit-wise logical operation specifiers]]// can get an equivalent effect by a technique such as the following. The order of the values in this "table" are such that ''([[CL:Functions:logand]] (boole ([[CL:Functions:elt]] boole-n-vector //n//) #b0101 #b0011) #b1111) → //n//''. <blockquote> ([[CL:Macros:defconstant]] boole-n-vector ([[CL:Functions:vector]] boole-clr boole-and boole-andc1 boole-2 boole-andc2 boole-1 boole-xor boole-ior boole-nor boole-eqv boole-c1 boole-orc1 boole-c2 boole-orc2 boole-nand boole-set)) <r>BOOLE-N-VECTOR </r> ([[CL:Functions:proclaim]] '([[CL:Declarations:inline]] boole-n)) <r>//[[CL:Glossary:implementation-dependent]]// </r> ([[CL:Macros:defun]] boole-n (n integer &rest more-integers) ([[CL:Functions:apply]] #'boole ([[CL:Functions:elt]] boole-n-vector n) integer more-integers)) <r>BOOLE-N </r> (boole-n #b0111 5 3) <r>7 </r> (boole-n #b0001 5 3) <r>1 </r> (boole-n #b1101 5 3) <r>-3 </r> ([[CL:Macros:loop]] for n from #b0000 to #b1111 collect (boole-n n 5 3)) <r>(0 1 2 3 4 5 6 7 -8 -7 -6 -5 -4 -3 -2 -1)</r> </blockquote>