118 lines
6.5 KiB
HTML
118 lines
6.5 KiB
HTML
![]() |
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
|
||
|
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
|
||
|
<HEAD>
|
||
|
<TITLE>17.4. Functions on Arrays of Bits</TITLE>
|
||
|
</HEAD>
|
||
|
<BODY>
|
||
|
<meta name="description" value=" Functions on Arrays of Bits">
|
||
|
<meta name="keywords" value="clm">
|
||
|
<meta name="resource-type" value="document">
|
||
|
<meta name="distribution" value="global">
|
||
|
<P>
|
||
|
<b>Common Lisp the Language, 2nd Edition</b>
|
||
|
<BR> <HR><A NAME=tex2html3537 HREF="node162.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html3535 HREF="node157.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html3529 HREF="node160.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html3539 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html3540 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html3538 HREF="node162.html"> Fill Pointers</A>
|
||
|
<B>Up:</B> <A NAME=tex2html3536 HREF="node157.html"> Arrays</A>
|
||
|
<B> Previous:</B> <A NAME=tex2html3530 HREF="node160.html"> Array Information</A>
|
||
|
<HR> <P>
|
||
|
<H1><A NAME=SECTION002140000000000000000>17.4. Functions on Arrays of Bits</A></H1>
|
||
|
<P>
|
||
|
The functions described in this section operate only
|
||
|
on arrays of bits, that is, specialized arrays whose elements
|
||
|
are all <tt>0</tt> or <tt>1</tt>.
|
||
|
<P>
|
||
|
<BR><b>[Function]</b><BR>
|
||
|
<tt>bit <i>bit-array</i> &rest <i>subscripts</i> <BR></tt><tt>sbit <i>simple-bit-array</i> &rest <i>subscripts</i></tt><P><tt>bit</tt> is exactly like <tt>aref</tt> but requires an array of bits,
|
||
|
that is, one of type <tt>(array bit)</tt>.
|
||
|
The result will always be <tt>0</tt> or <tt>1</tt>.
|
||
|
<tt>sbit</tt> is like <tt>bit</tt> but additionally requires that the first
|
||
|
argument be a <i>simple</i> array (see section <A HREF="node29.html#ARRAYTYPESECTION">2.5</A>).
|
||
|
Note that <tt>bit</tt> and <tt>sbit</tt>, unlike <tt>char</tt> and <tt>schar</tt>,
|
||
|
allow the first argument to be an array of any rank.
|
||
|
<P>
|
||
|
<tt>setf</tt> may be used with <tt>bit</tt> or <tt>sbit</tt> to destructively replace
|
||
|
a bit-array element with a new value.
|
||
|
<P>
|
||
|
<tt>bit</tt> and <tt>sbit</tt> are identical to <tt>aref</tt> except for the
|
||
|
more specific type requirements on the first argument.
|
||
|
In some implementations of Common Lisp,
|
||
|
<tt>bit</tt> may be faster than <tt>aref</tt> in situations where it is applicable,
|
||
|
and <tt>sbit</tt> may similarly be faster than <tt>bit</tt>.
|
||
|
<P>
|
||
|
<BR><b>[Function]</b><BR>
|
||
|
<pre>
|
||
|
<tt>bit-and <i>bit-array1</i> <i>bit-array2</i> &optional <i>result-bit-array</i>
|
||
|
bit-ior <i>bit-array1</i> <i>bit-array2</i> &optional <i>result-bit-array</i>
|
||
|
bit-xor <i>bit-array1</i> <i>bit-array2</i> &optional <i>result-bit-array</i>
|
||
|
bit-eqv <i>bit-array1</i> <i>bit-array2</i> &optional <i>result-bit-array</i>
|
||
|
bit-nand <i>bit-array1</i> <i>bit-array2</i> &optional <i>result-bit-array</i>
|
||
|
bit-nor <i>bit-array1</i> <i>bit-array2</i> &optional <i>result-bit-array</i>
|
||
|
bit-andc1 <i>bit-array1</i> <i>bit-array2</i> &optional <i>result-bit-array</i>
|
||
|
bit-andc2 <i>bit-array1</i> <i>bit-array2</i> &optional <i>result-bit-array</i>
|
||
|
bit-orc1 <i>bit-array1</i> <i>bit-array2</i> &optional <i>result-bit-array</i>
|
||
|
bit-orc2 <i>bit-array1</i> <i>bit-array2</i> &optional <i>result-bit-array</i></tt>
|
||
|
</pre>
|
||
|
<P>These functions perform bit-wise logical operations on bit-arrays.
|
||
|
All of the arguments to any of these functions must be bit-arrays
|
||
|
of the same rank and dimensions.
|
||
|
The result is a bit-array of matching rank and dimensions,
|
||
|
such that any given bit of the result
|
||
|
is produced by operating on corresponding bits from each of the arguments.
|
||
|
<P>
|
||
|
If the third argument is <tt>nil</tt> or omitted, a new array is created
|
||
|
to contain the result. If the third argument is a bit-array,
|
||
|
the result is destructively placed into that array. If the third
|
||
|
argument is <tt>t</tt>, then the first argument is also used as the third
|
||
|
argument; that is, the result is placed back in the first array.
|
||
|
<P>
|
||
|
The following table indicates what the result bit is for each operation
|
||
|
as a function of the two corresponding argument bits.
|
||
|
<pre>
|
||
|
<i>argument1</i> 0 0 1 1
|
||
|
<i>argument2</i> 0 1 0 1 <i>Operation name</i>
|
||
|
------------------------------------------------------------
|
||
|
bit-and 0 0 0 1 and
|
||
|
bit-ior 0 1 1 1 inclusive or
|
||
|
bit-xor 0 1 1 0 exclusive or
|
||
|
bit-eqv 1 0 0 1 equivalence (exclusive nor)
|
||
|
bit-nand 1 1 1 0 not-and
|
||
|
bit-nor 1 0 0 0 not-or
|
||
|
bit-andc1 0 1 0 0 and complement of <i>argument1</i> with <i>argument2</i>
|
||
|
bit-andc2 0 0 1 0 and <i>argument1</i> with complement of <i>argument2</i>
|
||
|
bit-orc1 1 1 0 1 or complement of <i>argument1</i> with <i>argument2</i>
|
||
|
bit-orc2 1 0 1 1 or <i>argument1</i> with complement of <i>argument2</i>
|
||
|
------------------------------------------------------------
|
||
|
</pre>
|
||
|
<P>
|
||
|
For example:
|
||
|
<P><pre>
|
||
|
(bit-and #*1100 #*1010) => #*1000
|
||
|
(bit-xor #*1100 #*1010) => #*0110
|
||
|
(bit-andc1 #*1100 #*1010) => #*0100
|
||
|
</pre><P>
|
||
|
See <tt>logand</tt> and related functions.
|
||
|
<P>
|
||
|
<BR><b>[Function]</b><BR>
|
||
|
<tt>bit-not <i>bit-array</i> &optional <i>result-bit-array</i></tt><P>The first argument must be an array of bits. A bit-array
|
||
|
of matching rank and dimensions is returned that contains
|
||
|
a copy of the argument
|
||
|
with all the bits inverted.
|
||
|
See <tt>lognot</tt>.
|
||
|
<P>
|
||
|
If the second argument is <tt>nil</tt> or omitted, a new array is created
|
||
|
to contain the result. If the second argument is a bit-array,
|
||
|
the result is destructively placed into that array. If the second
|
||
|
argument is <tt>t</tt>, then the first argument is also used as the second
|
||
|
argument; that is, the result is placed back in the first array.
|
||
|
<P>
|
||
|
<BR> <HR><A NAME=tex2html3537 HREF="node162.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html3535 HREF="node157.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html3529 HREF="node160.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html3539 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html3540 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html3538 HREF="node162.html"> Fill Pointers</A>
|
||
|
<B>Up:</B> <A NAME=tex2html3536 HREF="node157.html"> Arrays</A>
|
||
|
<B> Previous:</B> <A NAME=tex2html3530 HREF="node160.html"> Array Information</A>
|
||
|
<HR> <P>
|
||
|
<HR>
|
||
|
<P><ADDRESS>
|
||
|
AI.Repository@cs.cmu.edu
|
||
|
</ADDRESS>
|
||
|
</BODY>
|