⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bitstring-ops.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>2.1.4.1 Bit-string Operations on Integer Types </title>
<META NAME="description" CONTENT="2.1.4.1 Bit-string Operations on Integer Types ">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="previous" href="typesnumeric.html" tppabs="http://www.python.org/doc/current/lib/typesnumeric.html">
<LINK REL="up" href="typesnumeric.html" tppabs="http://www.python.org/doc/current/lib/typesnumeric.html">
<LINK REL="next" href="typesseq.html" tppabs="http://www.python.org/doc/current/lib/typesseq.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="typesnumeric.html" tppabs="http://www.python.org/doc/current/lib/typesnumeric.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="typesnumeric.html" tppabs="http://www.python.org/doc/current/lib/typesnumeric.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="typesseq.html" tppabs="http://www.python.org/doc/current/lib/typesseq.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="typesnumeric.html" tppabs="http://www.python.org/doc/current/lib/typesnumeric.html">2.1.4 Numeric Types</A>
<b class="navlabel">Up:</b> <a class="sectref" href="typesnumeric.html" tppabs="http://www.python.org/doc/current/lib/typesnumeric.html">2.1.4 Numeric Types</A>
<b class="navlabel">Next:</b> <a class="sectref" href="typesseq.html" tppabs="http://www.python.org/doc/current/lib/typesseq.html">2.1.5 Sequence Types</A>
<br><hr></DIV>
<!--End of Navigation Panel-->

<H3>
<BR>
2.1.4.1 Bit-string Operations on Integer Types 
</H3>

<P>
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 "<tt class="samp">~</tt>" has the same priority as the other unary numeric
operations ("<tt class="samp">+</tt>" and "<tt class="samp">-</tt>").

<P>
This table lists the bit-string operations sorted in ascending
priority (operations in the same box have the same priority):

<P>
<table border align="center" style="border-collapse: collapse">
  <thead>
    <tr>
      <th align="center"><b>Operation</b>&nbsp;</th>
      <th align="left"><b>Result</b>&nbsp;</th>
      <th align="center"><b>Notes</b>&nbsp;</th>
    </thead>
  <tbody valign='baseline'>
    <tr><td align="center" valign="baseline"><code><var>x</var> | <var>y</var></code></td>
        <td align="left">bitwise <i class="dfn">or</i> of <var>x</var> and <var>y</var></td>
        <td align="center">&nbsp;</td>
    <tr><td align="center" valign="baseline"><code><var>x</var> ^ <var>y</var></code></td>
        <td align="left">bitwise <i class="dfn">exclusive or</i> of <var>x</var> and <var>y</var></td>
        <td align="center">&nbsp;</td>
    <tr><td align="center" valign="baseline"><code><var>x</var> &amp; <var>y</var></code></td>
        <td align="left">bitwise <i class="dfn">and</i> of <var>x</var> and <var>y</var></td>
        <td align="center">&nbsp;</td>
    <tr><td align="center" valign="baseline"><code><var>x</var> &#171; <var>n</var></code></td>
        <td align="left"><var>x</var> shifted left by <var>n</var> bits</td>
        <td align="center">(1), (2)</td>
    <tr><td align="center" valign="baseline"><code><var>x</var> &#187; <var>n</var></code></td>
        <td align="left"><var>x</var> shifted right by <var>n</var> bits</td>
        <td align="center">(1), (3)</td>
  
    <tr><td align="center" valign="baseline"><code>~<var>x</var></code></td>
        <td align="left">the bits of <var>x</var> inverted</td>
        <td align="center">&nbsp;</td></tbody>
</table>


<P>
Notes:
<DL>
<DT><STRONG>(1)</STRONG></DT>
<DD>Negative shift counts are illegal and cause a
<tt class="exception">ValueError</tt> to be raised.
</DD>
<DT><STRONG>(2)</STRONG></DT>
<DD>A left shift by <var>n</var> bits is equivalent to
multiplication by <code>pow(2, <var>n</var>)</code> without overflow check.
</DD>
<DT><STRONG>(3)</STRONG></DT>
<DD>A right shift by <var>n</var> bits is equivalent to
division by <code>pow(2, <var>n</var>)</code> without overflow check.
</DD>
</DL>

<P>

<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="typesnumeric.html" tppabs="http://www.python.org/doc/current/lib/typesnumeric.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
  alt="Previous Page" width="32"></A></td>
<td><A href="typesnumeric.html" tppabs="http://www.python.org/doc/current/lib/typesnumeric.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
  alt="Up One Level" width="32"></A></td>
<td><A href="typesseq.html" tppabs="http://www.python.org/doc/current/lib/typesseq.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
  alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
  alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
  alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
  alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="typesnumeric.html" tppabs="http://www.python.org/doc/current/lib/typesnumeric.html">2.1.4 Numeric Types</A>
<b class="navlabel">Up:</b> <a class="sectref" href="typesnumeric.html" tppabs="http://www.python.org/doc/current/lib/typesnumeric.html">2.1.4 Numeric Types</A>
<b class="navlabel">Next:</b> <a class="sectref" href="typesseq.html" tppabs="http://www.python.org/doc/current/lib/typesseq.html">2.1.5 Sequence Types</A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -