home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 5
/
DATAFILE_PDCD5.iso
/
utilities
/
p
/
python
/
pyhtmldoc
/
b
/
bit-string
< prev
next >
Wrap
Text File
|
1996-11-14
|
2KB
|
38 lines
<TITLE>Bit-string Operations -- Python library reference</TITLE>
Prev: <A HREF="../n/numeric_types" TYPE="Prev">Numeric Types</A>
Up: <A HREF="../n/numeric_types" TYPE="Up">Numeric Types</A>
Top: <A HREF="../t/top" TYPE="Top">Top</A>
<H3>2.1.4.1. Bit-string Operations on Integer Types</H3>
Plain and long integer types support additional operations that make
sense only for bit-strings. Negative numbers are treated as their 2's
complement value (for long integers, this assumes a sufficiently large
number of bits that no overflow occurs during the operation).
<P>
The priorities of the binary bit-wise operations are all lower than
the numeric operations and higher than the comparisons; the unary
operation `<SAMP>~</SAMP>' has the same priority as the other unary numeric
operations (`<SAMP>+</SAMP>' and `<SAMP>-</SAMP>').
<P>
This table lists the bit-string operations sorted in ascending
priority (operations in the same box have the same priority):
<P>
<DL>
<DT><I>Operation</I><DD><I>Result</I> --- <I>Notes</I>
<P>
<DT><CODE><VAR>x</VAR> | <VAR>y</VAR></CODE><DD>bitwise <DFN>or</DFN> of <VAR>x</VAR> and <VAR>y</VAR>
<DT><CODE><VAR>x</VAR> ^ <VAR>y</VAR></CODE><DD>bitwise <DFN>exclusive or</DFN> of <VAR>x</VAR> and <VAR>y</VAR>
<DT><CODE><VAR>x</VAR> & <VAR>y</VAR></CODE><DD>bitwise <DFN>and</DFN> of <VAR>x</VAR> and <VAR>y</VAR>
<DT><CODE><VAR>x</VAR> << <VAR>n</VAR></CODE><DD><VAR>x</VAR> shifted left by <VAR>n</VAR> bits --- (1), (2)
<DT><CODE><VAR>x</VAR> >> <VAR>n</VAR></CODE><DD><VAR>x</VAR> shifted right by <VAR>n</VAR> bits --- (1), (3)
@hline@hline
<DT><CODE>~<VAR>x</VAR></CODE><DD>the bits of <VAR>x</VAR> inverted
</DL>
Notes:
<DL>
<DT><B>(1)</B><DD>Negative shift counts are illegal.
<DT><B>(2)</B><DD>A left shift by <VAR>n</VAR> bits is equivalent to
multiplication by <CODE>pow(2, <VAR>n</VAR>)</CODE> without overflow check.
<DT><B>(3)</B><DD>A right shift by <VAR>n</VAR> bits is equivalent to
division by <CODE>pow(2, <VAR>n</VAR>)</CODE> without overflow check.
</DL>