141 lines
8.3 KiB
HTML
141 lines
8.3 KiB
HTML
|
<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
|
||
|
<HTML>
|
||
|
<HEAD>
|
||
|
<TITLE>CLHS: Function LOGAND, LOGANDC1, LOGANDC2...</TITLE>
|
||
|
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
|
||
|
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
|
||
|
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
|
||
|
<LINK REL=TOP HREF="../Front/index.htm">
|
||
|
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
|
||
|
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
|
||
|
<LINK REL=PREV HREF="v_b_1_b.htm">
|
||
|
<LINK REL=UP HREF="c_number.htm">
|
||
|
<LINK REL=NEXT HREF="f_logbtp.htm">
|
||
|
</HEAD>
|
||
|
<BODY>
|
||
|
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="v_b_1_b.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_number.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="f_logbtp.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
||
|
|
||
|
<HR>
|
||
|
|
||
|
<A NAME="logand"><A NAME="logandc1"><A NAME="logandc2"><A NAME="logeqv"><A NAME="logior"><A NAME="lognand"><A NAME="lognor"><A NAME="lognot"><A NAME="logorc1"><A NAME="logorc2"><A NAME="logxor"><I>Function</I> <B>LOGAND, LOGANDC1, LOGANDC2, LOGEQV, LOGIOR, LOGNAND, LOGNOR, LOGNOT, LOGORC1, LOGORC2, LOGXOR</B></A></A></A></A></A></A></A></A></A></A></A> <P>
|
||
|
<P><B>Syntax:</B><P>
|
||
|
<P>
|
||
|
|
||
|
<B>logand</B> <I><TT>&rest</TT> integers</I> => <I>result-integer</I><P>
|
||
|
|
||
|
<B>logandc1</B> <I>integer-1 integer-2</I> => <I>result-integer</I><P>
|
||
|
|
||
|
<B>logandc2</B> <I>integer-1 integer-2</I> => <I>result-integer</I><P>
|
||
|
|
||
|
<B>logeqv</B> <I><TT>&rest</TT> integers</I> => <I>result-integer</I><P>
|
||
|
|
||
|
<B>logior</B> <I><TT>&rest</TT> integers</I> => <I>result-integer</I><P>
|
||
|
|
||
|
<B>lognand</B> <I>integer-1 integer-2</I> => <I>result-integer</I><P>
|
||
|
|
||
|
<B>lognor</B> <I>integer-1 integer-2</I> => <I>result-integer</I><P>
|
||
|
|
||
|
<B>lognot</B> <I>integer</I> => <I>result-integer</I><P>
|
||
|
|
||
|
<B>logorc1</B> <I>integer-1 integer-2</I> => <I>result-integer</I><P>
|
||
|
|
||
|
<B>logorc2</B> <I>integer-1 integer-2</I> => <I>result-integer</I><P>
|
||
|
|
||
|
<B>logxor</B> <I><TT>&rest</TT> integers</I> => <I>result-integer</I><P>
|
||
|
<P>
|
||
|
<P><B>Arguments and Values:</B><P>
|
||
|
<P>
|
||
|
<I>integers</I>---<A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integers</I></A>. <P>
|
||
|
<I>integer</I>---an <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>. <P>
|
||
|
<I>integer-1</I>---an <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>. <P>
|
||
|
<I>integer-2</I>---an <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>. <P>
|
||
|
<I>result-integer</I>---an <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>. <P>
|
||
|
<P><B>Description:</B><P>
|
||
|
<P>
|
||
|
The <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>functions</I></A> <A REL=DEFINITION HREF="#logandc1"><B>logandc1</B></A>, <A REL=DEFINITION HREF="#logandc2"><B>logandc2</B></A>, <A REL=DEFINITION HREF="#logand"><B>logand</B></A>, <A REL=DEFINITION HREF="#logeqv"><B>logeqv</B></A>, <A REL=DEFINITION HREF="#logior"><B>logior</B></A>, <A REL=DEFINITION HREF="#lognand"><B>lognand</B></A>, <A REL=DEFINITION HREF="#lognor"><B>lognor</B></A>, <A REL=DEFINITION HREF="#lognot"><B>lognot</B></A>, <A REL=DEFINITION HREF="#logorc1"><B>logorc1</B></A>, <A REL=DEFINITION HREF="#logorc2"><B>logorc2</B></A>, and <A REL=DEFINITION HREF="#logxor"><B>logxor</B></A> perform bit-wise logical operations on their <A REL=DEFINITION HREF="26_glo_a.htm#argument"><I>arguments</I></A>, that are treated as if they were binary. <P>
|
||
|
The next figure lists the meaning of each of the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>functions</I></A>. Where an `identity' is shown, it indicates the <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A> <I>yielded</I> by the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> when no <A REL=DEFINITION HREF="26_glo_a.htm#argument"><I>arguments</I></A> are supplied. <P>
|
||
|
<PRE>
|
||
|
Function Identity Operation performed
|
||
|
<A REL=DEFINITION HREF="#logandc1">logandc1</A> --- and complement of integer-1 with integer-2
|
||
|
<A REL=DEFINITION HREF="#logandc2">logandc2</A> --- and integer-1 with complement of integer-2
|
||
|
<A REL=DEFINITION HREF="#logand">logand</A> -1 and
|
||
|
<A REL=DEFINITION HREF="#logeqv">logeqv</A> -1 equivalence (exclusive nor)
|
||
|
<A REL=DEFINITION HREF="#logior">logior</A> 0 inclusive or
|
||
|
<A REL=DEFINITION HREF="#lognand">lognand</A> --- complement of integer-1 and integer-2
|
||
|
<A REL=DEFINITION HREF="#lognor">lognor</A> --- complement of integer-1 or integer-2
|
||
|
<A REL=DEFINITION HREF="#lognot">lognot</A> --- complement
|
||
|
<A REL=DEFINITION HREF="#logorc1">logorc1</A> --- or complement of integer-1 with integer-2
|
||
|
<A REL=DEFINITION HREF="#logorc2">logorc2</A> --- or integer-1 with complement of integer-2
|
||
|
<A REL=DEFINITION HREF="#logxor">logxor</A> 0 exclusive or
|
||
|
</PRE>
|
||
|
<P><B>Figure 12-18. Bit-wise Logical Operations on Integers</B> <P>
|
||
|
Negative <I>integers</I> are treated as if they were in two's-complement notation. <P>
|
||
|
<P><B>Examples:</B><P>
|
||
|
<P>
|
||
|
<PRE>
|
||
|
(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
|
||
|
</PRE>
|
||
|
</TT> <P>
|
||
|
<P><B>Side Effects:</B> None.
|
||
|
<P>
|
||
|
<P><B>Affected By:</B> None.
|
||
|
<P>
|
||
|
<P><B>Exceptional Situations:</B><P>
|
||
|
<P>
|
||
|
Should signal <A REL=DEFINITION HREF="e_tp_err.htm#type-error"><B>type-error</B></A> if any argument is not an <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>. <P>
|
||
|
<P><B>See Also:</B><P>
|
||
|
<P>
|
||
|
<A REL=DEFINITION HREF="f_boole.htm#boole"><B>boole</B></A> <P>
|
||
|
<P><B>Notes:</B><P>
|
||
|
<P>
|
||
|
<TT>(logbitp </TT><I>k</I><TT> -1)</TT> returns <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A> for all values of <I>k</I>. <P>
|
||
|
Because the following functions are not associative, they take exactly two arguments rather than any number of arguments. <P>
|
||
|
<PRE>
|
||
|
(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))
|
||
|
</PRE>
|
||
|
</TT> <P>
|
||
|
<HR>
|
||
|
|
||
|
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
|
||
|
|
||
|
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
|
||
|
</BODY>
|
||
|
</HTML>
|