Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / html / python / lib / bitstring-ops.html
CommitLineData
86530b38
AT
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="lib.css" type='text/css' />
5<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
6<link rel='start' href='../index.html' title='Python Documentation Index' />
7<link rel="first" href="lib.html" title='Python Library Reference' />
8<link rel='contents' href='contents.html' title="Contents" />
9<link rel='index' href='genindex.html' title='Index' />
10<link rel='last' href='about.html' title='About this document...' />
11<link rel='help' href='about.html' title='About this document...' />
12<link rel="prev" href="typesnumeric.html" />
13<link rel="parent" href="typesnumeric.html" />
14<link rel="next" href="typeiter.html" />
15<meta name='aesop' content='information' />
16<title>2.3.4.1 Bit-string Operations on Integer Types </title>
17</head>
18<body>
19<DIV CLASS="navigation">
20<div id='top-navigation-panel' xml:id='top-navigation-panel'>
21<table align="center" width="100%" cellpadding="0" cellspacing="2">
22<tr>
23<td class='online-navigation'><a rel="prev" title="2.3.4 Numeric Types "
24 href="typesnumeric.html"><img src='../icons/previous.png'
25 border='0' height='32' alt='Previous Page' width='32' /></A></td>
26<td class='online-navigation'><a rel="parent" title="2.3.4 Numeric Types "
27 href="typesnumeric.html"><img src='../icons/up.png'
28 border='0' height='32' alt='Up One Level' width='32' /></A></td>
29<td class='online-navigation'><a rel="next" title="2.3.5 Iterator Types"
30 href="typeiter.html"><img src='../icons/next.png'
31 border='0' height='32' alt='Next Page' width='32' /></A></td>
32<td align="center" width="100%">Python Library Reference</td>
33<td class='online-navigation'><a rel="contents" title="Table of Contents"
34 href="contents.html"><img src='../icons/contents.png'
35 border='0' height='32' alt='Contents' width='32' /></A></td>
36<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
37 border='0' height='32' alt='Module Index' width='32' /></a></td>
38<td class='online-navigation'><a rel="index" title="Index"
39 href="genindex.html"><img src='../icons/index.png'
40 border='0' height='32' alt='Index' width='32' /></A></td>
41</tr></table>
42<div class='online-navigation'>
43<b class="navlabel">Previous:</b>
44<a class="sectref" rel="prev" href="typesnumeric.html">2.3.4 Numeric Types </A>
45<b class="navlabel">Up:</b>
46<a class="sectref" rel="parent" href="typesnumeric.html">2.3.4 Numeric Types </A>
47<b class="navlabel">Next:</b>
48<a class="sectref" rel="next" href="typeiter.html">2.3.5 Iterator Types</A>
49</div>
50<hr /></div>
51</DIV>
52<!--End of Navigation Panel-->
53
54<H3><A NAME="SECTION004341000000000000000"></A><A NAME="bitstring-ops"></A>
55<BR>
562.3.4.1 Bit-string Operations on Integer Types
57</H3>
58<A NAME="Bit-string_Operations"></A>
59<P>
60Plain and long integer types support additional operations that make
61sense only for bit-strings. Negative numbers are treated as their 2's
62complement value (for long integers, this assumes a sufficiently large
63number of bits that no overflow occurs during the operation).
64
65<P>
66The priorities of the binary bit-wise operations are all lower than
67the numeric operations and higher than the comparisons; the unary
68operation "<tt class="samp">~</tt>" has the same priority as the other unary numeric
69operations ("<tt class="samp">+</tt>" and "<tt class="samp">-</tt>").
70
71<P>
72This table lists the bit-string operations sorted in ascending
73priority (operations in the same box have the same priority):
74
75<P>
76<div class="center"><table class="realtable">
77 <thead>
78 <tr>
79 <th class="center">Operation</th>
80 <th class="left" >Result</th>
81 <th class="center">Notes</th>
82 </tr>
83 </thead>
84 <tbody>
85 <tr><td class="center" valign="baseline"><code><var>x</var> | <var>y</var></code></td>
86 <td class="left" >bitwise <i class="dfn">or</i> of <var>x</var> and <var>y</var></td>
87 <td class="center"></td></tr>
88 <tr><td class="center" valign="baseline"><code><var>x</var> ^ <var>y</var></code></td>
89 <td class="left" >bitwise <i class="dfn">exclusive or</i> of <var>x</var> and <var>y</var></td>
90 <td class="center"></td></tr>
91 <tr><td class="center" valign="baseline"><code><var>x</var> &amp; <var>y</var></code></td>
92 <td class="left" >bitwise <i class="dfn">and</i> of <var>x</var> and <var>y</var></td>
93 <td class="center"></td></tr>
94 <tr><td class="center" valign="baseline"><code><var>x</var> &lt;&lt; <var>n</var></code></td>
95 <td class="left" ><var>x</var> shifted left by <var>n</var> bits</td>
96 <td class="center">(1), (2)</td></tr>
97 <tr><td class="center" valign="baseline"><code><var>x</var> &gt;&gt; <var>n</var></code></td>
98 <td class="left" ><var>x</var> shifted right by <var>n</var> bits</td>
99 <td class="center">(1), (3)</td></tr>
100
101 <tr><td class="center" valign="baseline"><code>~<var>x</var></code></td>
102 <td class="left" >the bits of <var>x</var> inverted</td>
103 <td class="center"></td></tr></tbody>
104</table></div>
105<a id='l2h-148' xml:id='l2h-148'></a><a id='l2h-149' xml:id='l2h-149'></a><a id='l2h-150' xml:id='l2h-150'></a><a id='l2h-151' xml:id='l2h-151'></a>
106<P>
107Notes:
108<DL>
109<DT><STRONG>(1)</STRONG></DT>
110<DD>Negative shift counts are illegal and cause a
111<tt class="exception">ValueError</tt> to be raised.
112</DD>
113<DT><STRONG>(2)</STRONG></DT>
114<DD>A left shift by <var>n</var> bits is equivalent to
115multiplication by <code>pow(2, <var>n</var>)</code> without overflow check.
116</DD>
117<DT><STRONG>(3)</STRONG></DT>
118<DD>A right shift by <var>n</var> bits is equivalent to
119division by <code>pow(2, <var>n</var>)</code> without overflow check.
120</DD>
121</DL>
122
123<P>
124
125<DIV CLASS="navigation">
126<div class='online-navigation'>
127<p></p><hr />
128<table align="center" width="100%" cellpadding="0" cellspacing="2">
129<tr>
130<td class='online-navigation'><a rel="prev" title="2.3.4 Numeric Types "
131 href="typesnumeric.html"><img src='../icons/previous.png'
132 border='0' height='32' alt='Previous Page' width='32' /></A></td>
133<td class='online-navigation'><a rel="parent" title="2.3.4 Numeric Types "
134 href="typesnumeric.html"><img src='../icons/up.png'
135 border='0' height='32' alt='Up One Level' width='32' /></A></td>
136<td class='online-navigation'><a rel="next" title="2.3.5 Iterator Types"
137 href="typeiter.html"><img src='../icons/next.png'
138 border='0' height='32' alt='Next Page' width='32' /></A></td>
139<td align="center" width="100%">Python Library Reference</td>
140<td class='online-navigation'><a rel="contents" title="Table of Contents"
141 href="contents.html"><img src='../icons/contents.png'
142 border='0' height='32' alt='Contents' width='32' /></A></td>
143<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
144 border='0' height='32' alt='Module Index' width='32' /></a></td>
145<td class='online-navigation'><a rel="index" title="Index"
146 href="genindex.html"><img src='../icons/index.png'
147 border='0' height='32' alt='Index' width='32' /></A></td>
148</tr></table>
149<div class='online-navigation'>
150<b class="navlabel">Previous:</b>
151<a class="sectref" rel="prev" href="typesnumeric.html">2.3.4 Numeric Types </A>
152<b class="navlabel">Up:</b>
153<a class="sectref" rel="parent" href="typesnumeric.html">2.3.4 Numeric Types </A>
154<b class="navlabel">Next:</b>
155<a class="sectref" rel="next" href="typeiter.html">2.3.5 Iterator Types</A>
156</div>
157</div>
158<hr />
159<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
160</DIV>
161<!--End of Navigation Panel-->
162<ADDRESS>
163See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
164</ADDRESS>
165</BODY>
166</HTML>