/usr/share/doc/python-bitstring-doc/html/bitarray.html is in python-bitstring-doc 3.1.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 | <!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The BitArray class — bitstring documentation</title>
<link rel="stylesheet" href="_static/bizstyle.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '3.1.4',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/bizstyle.js"></script>
<link rel="top" title="bitstring documentation" href="index.html" />
<link rel="up" title="Reference" href="reference.html" />
<link rel="next" title="The ConstBitStream class" href="constbitstream.html" />
<link rel="prev" title="The Bits class" href="constbitarray.html" />
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<!--[if lt IE 9]>
<script type="text/javascript" src="_static/css3-mediaqueries.js"></script>
<![endif]-->
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="constbitstream.html" title="The ConstBitStream class"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="constbitarray.html" title="The Bits class"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">bitstring</a> »</li>
<li class="nav-item nav-item-1"><a href="reference.html" accesskey="U">Reference</a> »</li>
</ul>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="index.html">
<img class="logo" src="_static/bitstring_logo_small.png" alt="Logo"/>
</a></p>
<h4>Previous topic</h4>
<p class="topless"><a href="constbitarray.html"
title="previous chapter">The Bits class</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="constbitstream.html"
title="next chapter">The ConstBitStream class</a></p>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="the-bitarray-class">
<h1>The BitArray class<a class="headerlink" href="#the-bitarray-class" title="Permalink to this headline">¶</a></h1>
<dl class="class">
<dt id="bitstring.BitArray">
<em class="property">class </em><code class="descclassname">bitstring.</code><code class="descname">BitArray</code><span class="sig-paren">(</span><span class="optional">[</span><em>auto</em>, <em>length</em>, <em>offset</em>, <em>**kwargs</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray" title="Permalink to this definition">¶</a></dt>
<dd><p>The <a class="reference internal" href="constbitarray.html#bitstring.Bits" title="bitstring.Bits"><code class="xref py py-class docutils literal"><span class="pre">Bits</span></code></a> class is the base class for <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a> and so (with the exception of <a class="reference internal" href="constbitarray.html#bitstring.Bits.__hash__" title="bitstring.Bits.__hash__"><code class="xref py py-meth docutils literal"><span class="pre">__hash__</span></code></a>) all of its methods are also available for <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a> objects. The initialiser is also the same as for <a class="reference internal" href="constbitarray.html#bitstring.Bits" title="bitstring.Bits"><code class="xref py py-class docutils literal"><span class="pre">Bits</span></code></a> and so won’t be repeated here.</p>
<p>A <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a> is a mutable <a class="reference internal" href="constbitarray.html#bitstring.Bits" title="bitstring.Bits"><code class="xref py py-class docutils literal"><span class="pre">Bits</span></code></a>, and so the one thing all of the methods listed here have in common is that they can modify the contents of the bitstring.</p>
<dl class="method">
<dt id="bitstring.BitArray.append">
<code class="descname">append</code><span class="sig-paren">(</span><em>bs</em><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.append" title="Permalink to this definition">¶</a></dt>
<dd><p>Join a <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a> to the end of the current <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a>.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="n">BitArray</span><span class="p">(</span><span class="s1">'0xbad'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">'0xf00d'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span>
<span class="go">BitArray('0xbadf00d')</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.byteswap">
<code class="descname">byteswap</code><span class="sig-paren">(</span><span class="optional">[</span><em>fmt</em>, <em>start</em>, <em>end</em>, <em>repeat=True</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.byteswap" title="Permalink to this definition">¶</a></dt>
<dd><p>Change the endianness of the <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a> in-place according to <em>fmt</em>. Return the number of swaps done.</p>
<p>The <em>fmt</em> can be an integer, an iterable of integers or a compact format string similar to those used in <a class="reference internal" href="functions.html#bitstring.pack" title="bitstring.pack"><code class="xref py py-func docutils literal"><span class="pre">pack</span></code></a> (described in <a class="reference internal" href="packing.html#compact-format"><span>Compact format strings</span></a>). It defaults to 0, which means reverse as many bytes as possible. The <em>fmt</em> gives a pattern of byte sizes to use to swap the endianness of the <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a>. Note that if you use a compact format string then the endianness identifier (<code class="docutils literal"><span class="pre"><</span></code>, <code class="docutils literal"><span class="pre">></span></code> or <code class="docutils literal"><span class="pre">@</span></code>) is not needed, and if present it will be ignored.</p>
<p><em>start</em> and <em>end</em> optionally give a slice to apply the transformation to (it defaults to the whole <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a>). If <em>repeat</em> is <code class="docutils literal"><span class="pre">True</span></code> then the byte swapping pattern given by the <em>fmt</em> is repeated in its entirety as many times as possible.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="n">BitArray</span><span class="p">(</span><span class="s1">'0x00112233445566'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">byteswap</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">3</span>
<span class="gp">>>> </span><span class="n">s</span>
<span class="go">BitArray('0x11003322554466')</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">byteswap</span><span class="p">(</span><span class="s1">'h'</span><span class="p">)</span>
<span class="go">3</span>
<span class="gp">>>> </span><span class="n">s</span>
<span class="go">BitArray('0x00112233445566')</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">byteswap</span><span class="p">([</span><span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">])</span>
<span class="go">1</span>
<span class="gp">>>> </span><span class="n">s</span>
<span class="go">BitArray('0x11006655443322')</span>
</pre></div>
</div>
<p>It can also be used to swap the endianness of the whole <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a>.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="n">BitArray</span><span class="p">(</span><span class="s1">'uintle:32=1234'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">byteswap</span><span class="p">()</span>
<span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">uintbe</span><span class="p">)</span>
<span class="go">1234</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.clear">
<code class="descname">clear</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.clear" title="Permalink to this definition">¶</a></dt>
<dd><p>Removes all bits from the bitstring.</p>
<p><code class="docutils literal"><span class="pre">s.clear()</span></code> is equivalent to <code class="docutils literal"><span class="pre">del</span> <span class="pre">s[:]</span></code> and simply makes the bitstring empty.</p>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.copy">
<code class="descname">copy</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.copy" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a copy of the bitstring.</p>
<p><code class="docutils literal"><span class="pre">s.copy()</span></code> is equivalent to the shallow copy <code class="docutils literal"><span class="pre">s[:]</span></code> and creates a new copy of the bitstring in memory.</p>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.insert">
<code class="descname">insert</code><span class="sig-paren">(</span><em>bs</em>, <em>pos</em><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.insert" title="Permalink to this definition">¶</a></dt>
<dd><p>Inserts <em>bs</em> at <em>pos</em>.</p>
<p>When used with the <a class="reference internal" href="bitstream.html#bitstring.BitStream" title="bitstring.BitStream"><code class="xref py py-class docutils literal"><span class="pre">BitStream</span></code></a> class the <em>pos</em> is optional, and if not present the current bit position will be used. After insertion the property <a class="reference internal" href="constbitstream.html#bitstring.ConstBitStream.pos" title="bitstring.ConstBitStream.pos"><code class="xref py py-attr docutils literal"><span class="pre">pos</span></code></a> will be immediately after the inserted bitstring.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="n">BitStream</span><span class="p">(</span><span class="s1">'0xccee'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="s1">'0xd'</span><span class="p">,</span> <span class="mi">8</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span>
<span class="go">BitStream('0xccdee')</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="s1">'0x00'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span>
<span class="go">BitStream('0xccd00ee')</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.invert">
<code class="descname">invert</code><span class="sig-paren">(</span><span class="optional">[</span><em>pos</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.invert" title="Permalink to this definition">¶</a></dt>
<dd><p>Inverts one or many bits from <code class="docutils literal"><span class="pre">1</span></code> to <code class="docutils literal"><span class="pre">0</span></code> or vice versa.</p>
<p><em>pos</em> can be either a single bit position or an iterable of bit positions. Negative numbers are treated in the same way as slice indices and it will raise <code class="xref py py-exc docutils literal"><span class="pre">IndexError</span></code> if <code class="docutils literal"><span class="pre">pos</span> <span class="pre"><</span> <span class="pre">-s.len</span></code> or <code class="docutils literal"><span class="pre">pos</span> <span class="pre">></span> <span class="pre">s.len</span></code>. The default is to invert the entire <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a>.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="n">BitArray</span><span class="p">(</span><span class="s1">'0b111001'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">invert</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">bin</span>
<span class="go">'011001'</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">invert</span><span class="p">([</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">bin</span>
<span class="go">'011010'</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">invert</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">bin</span>
<span class="go">'100101'</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.overwrite">
<code class="descname">overwrite</code><span class="sig-paren">(</span><em>bs</em>, <em>pos</em><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.overwrite" title="Permalink to this definition">¶</a></dt>
<dd><p>Replaces the contents of the current <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a> with <em>bs</em> at <em>pos</em>.</p>
<p>When used with the <a class="reference internal" href="bitstream.html#bitstring.BitStream" title="bitstring.BitStream"><code class="xref py py-class docutils literal"><span class="pre">BitStream</span></code></a> class the <em>pos</em> is optional, and if not present the current bit position will be used. After insertion the property <a class="reference internal" href="constbitstream.html#bitstring.ConstBitStream.pos" title="bitstring.ConstBitStream.pos"><code class="xref py py-attr docutils literal"><span class="pre">pos</span></code></a> will be immediately after the overwritten bitstring.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="n">BitArray</span><span class="p">(</span><span class="n">length</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">overwrite</span><span class="p">(</span><span class="s1">'0b111'</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span>
<span class="go">BitArray('0b0001110000')</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">pos</span>
<span class="go">6</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.prepend">
<code class="descname">prepend</code><span class="sig-paren">(</span><em>bs</em><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.prepend" title="Permalink to this definition">¶</a></dt>
<dd><p>Inserts <em>bs</em> at the beginning of the current <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a>.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="n">BitArray</span><span class="p">(</span><span class="s1">'0b0'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">prepend</span><span class="p">(</span><span class="s1">'0xf'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span>
<span class="go">BitArray('0b11110')</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.replace">
<code class="descname">replace</code><span class="sig-paren">(</span><em>old</em>, <em>new</em><span class="optional">[</span>, <em>start</em>, <em>end</em>, <em>count</em>, <em>bytealigned</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.replace" title="Permalink to this definition">¶</a></dt>
<dd><p>Finds occurrences of <em>old</em> and replaces them with <em>new</em>. Returns the number of replacements made.</p>
<p>If <em>bytealigned</em> is <code class="docutils literal"><span class="pre">True</span></code> then replacements will only be made on byte boundaries. <em>start</em> and <em>end</em> give the search range and default to <code class="docutils literal"><span class="pre">0</span></code> and <a class="reference internal" href="constbitarray.html#bitstring.Bits.len" title="bitstring.Bits.len"><code class="xref py py-attr docutils literal"><span class="pre">len</span></code></a> respectively. If <em>count</em> is specified then no more than this many replacements will be made.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="n">BitArray</span><span class="p">(</span><span class="s1">'0b0011001'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'0b1'</span><span class="p">,</span> <span class="s1">'0xf'</span><span class="p">)</span>
<span class="go">3</span>
<span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">bin</span><span class="p">)</span>
<span class="go">0011111111001111</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">'0b1'</span><span class="p">,</span> <span class="s1">''</span><span class="p">,</span> <span class="n">count</span><span class="o">=</span><span class="mi">6</span><span class="p">)</span>
<span class="go">6</span>
<span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">bin</span><span class="p">)</span>
<span class="go">0011001111</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.reverse">
<code class="descname">reverse</code><span class="sig-paren">(</span><span class="optional">[</span><em>start</em>, <em>end</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.reverse" title="Permalink to this definition">¶</a></dt>
<dd><p>Reverses bits in the <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a> in-place.</p>
<p><em>start</em> and <em>end</em> give the range and default to <code class="docutils literal"><span class="pre">0</span></code> and <a class="reference internal" href="constbitarray.html#bitstring.Bits.len" title="bitstring.Bits.len"><code class="xref py py-attr docutils literal"><span class="pre">len</span></code></a> respectively.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">BitArray</span><span class="p">(</span><span class="s1">'0b10111'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">a</span><span class="o">.</span><span class="n">reverse</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">a</span><span class="o">.</span><span class="n">bin</span>
<span class="go">'11101'</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.rol">
<code class="descname">rol</code><span class="sig-paren">(</span><em>bits</em><span class="optional">[</span>, <em>start</em>, <em>end</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.rol" title="Permalink to this definition">¶</a></dt>
<dd><p>Rotates the contents of the <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a> in-place by <em>bits</em> bits to the left.</p>
<p><em>start</em> and <em>end</em> define the slice to use and default to <code class="docutils literal"><span class="pre">0</span></code> and <a class="reference internal" href="constbitarray.html#bitstring.Bits.len" title="bitstring.Bits.len"><code class="xref py py-attr docutils literal"><span class="pre">len</span></code></a> respectively.</p>
<p>Raises <code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code> if <code class="docutils literal"><span class="pre">bits</span> <span class="pre"><</span> <span class="pre">0</span></code>.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="n">BitArray</span><span class="p">(</span><span class="s1">'0b01000001'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">rol</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">bin</span>
<span class="go">'00000101'</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.ror">
<code class="descname">ror</code><span class="sig-paren">(</span><em>bits</em><span class="optional">[</span>, <em>start</em>, <em>end</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.ror" title="Permalink to this definition">¶</a></dt>
<dd><p>Rotates the contents of the <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a> in-place by <em>bits</em> bits to the right.</p>
<p><em>start</em> and <em>end</em> define the slice to use and default to <code class="docutils literal"><span class="pre">0</span></code> and <a class="reference internal" href="constbitarray.html#bitstring.Bits.len" title="bitstring.Bits.len"><code class="xref py py-attr docutils literal"><span class="pre">len</span></code></a> respectively.</p>
<p>Raises <code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code> if <code class="docutils literal"><span class="pre">bits</span> <span class="pre"><</span> <span class="pre">0</span></code>.</p>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.set">
<code class="descname">set</code><span class="sig-paren">(</span><em>value</em><span class="optional">[</span>, <em>pos</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.set" title="Permalink to this definition">¶</a></dt>
<dd><p>Sets one or many bits to either <code class="docutils literal"><span class="pre">1</span></code> (if <em>value</em> is <code class="docutils literal"><span class="pre">True</span></code>) or <code class="docutils literal"><span class="pre">0</span></code> (if <em>value</em> isn’t <code class="docutils literal"><span class="pre">True</span></code>). <em>pos</em> can be either a single bit position or an iterable of bit positions. Negative numbers are treated in the same way as slice indices and it will raise <code class="xref py py-exc docutils literal"><span class="pre">IndexError</span></code> if <code class="docutils literal"><span class="pre">pos</span> <span class="pre"><</span> <span class="pre">-s.len</span></code> or <code class="docutils literal"><span class="pre">pos</span> <span class="pre">></span> <span class="pre">s.len</span></code>. The default is to set every bit in the <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a>.</p>
<p>Using <code class="docutils literal"><span class="pre">s.set(True,</span> <span class="pre">x)</span></code> can be more efficent than other equivalent methods such as <code class="docutils literal"><span class="pre">s[x]</span> <span class="pre">=</span> <span class="pre">1</span></code>, <code class="docutils literal"><span class="pre">s[x]</span> <span class="pre">=</span> <span class="pre">"0b1"</span></code> or <code class="docutils literal"><span class="pre">s.overwrite('0b1',</span> <span class="pre">x)</span></code>, especially if many bits are being set.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="n">BitArray</span><span class="p">(</span><span class="s1">'0x0000'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="bp">True</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
<span class="go">0x0001</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">9</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">bin</span>
<span class="go">'1000110101000001'</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">bin</span>
<span class="go">'0000000000000000'</span>
</pre></div>
</div>
</dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.bin">
<code class="descname">bin</code><a class="headerlink" href="#bitstring.BitArray.bin" title="Permalink to this definition">¶</a></dt>
<dd><p>Writable version of <a class="reference internal" href="constbitarray.html#bitstring.Bits.bin" title="bitstring.Bits.bin"><code class="xref py py-attr docutils literal"><span class="pre">Bits.bin</span></code></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.bool">
<code class="descname">bool</code><a class="headerlink" href="#bitstring.BitArray.bool" title="Permalink to this definition">¶</a></dt>
<dd><p>Writable version of <a class="reference internal" href="constbitarray.html#bitstring.Bits.bool" title="bitstring.Bits.bool"><code class="xref py py-attr docutils literal"><span class="pre">Bits.bool</span></code></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.bytes">
<code class="descname">bytes</code><a class="headerlink" href="#bitstring.BitArray.bytes" title="Permalink to this definition">¶</a></dt>
<dd><p>Writable version of <a class="reference internal" href="constbitarray.html#bitstring.Bits.bytes" title="bitstring.Bits.bytes"><code class="xref py py-attr docutils literal"><span class="pre">Bits.bytes</span></code></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.hex">
<code class="descname">hex</code><a class="headerlink" href="#bitstring.BitArray.hex" title="Permalink to this definition">¶</a></dt>
<dd><p>Writable version of <a class="reference internal" href="constbitarray.html#bitstring.Bits.hex" title="bitstring.Bits.hex"><code class="xref py py-attr docutils literal"><span class="pre">Bits.hex</span></code></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.int">
<code class="descname">int</code><a class="headerlink" href="#bitstring.BitArray.int" title="Permalink to this definition">¶</a></dt>
<dd><p>Writable version of <a class="reference internal" href="constbitarray.html#bitstring.Bits.int" title="bitstring.Bits.int"><code class="xref py py-attr docutils literal"><span class="pre">Bits.int</span></code></a>.</p>
<p>When used as a setter the value must fit into the current length of the <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a>, else a <code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code> will be raised.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="n">BitArray</span><span class="p">(</span><span class="s1">'0xf3'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">int</span>
<span class="go">-13</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">int</span> <span class="o">=</span> <span class="mi">1232</span>
<span class="go">ValueError: int 1232 is too large for a BitArray of length 8.</span>
</pre></div>
</div>
</dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.intbe">
<code class="descname">intbe</code><a class="headerlink" href="#bitstring.BitArray.intbe" title="Permalink to this definition">¶</a></dt>
<dd><p>Writable version of <a class="reference internal" href="constbitarray.html#bitstring.Bits.intbe" title="bitstring.Bits.intbe"><code class="xref py py-attr docutils literal"><span class="pre">Bits.intbe</span></code></a>.</p>
<p>When used as a setter the value must fit into the current length of the <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a>, else a <code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code> will be raised.</p>
</dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.intle">
<code class="descname">intle</code><a class="headerlink" href="#bitstring.BitArray.intle" title="Permalink to this definition">¶</a></dt>
<dd><p>Writable version of <a class="reference internal" href="constbitarray.html#bitstring.Bits.intle" title="bitstring.Bits.intle"><code class="xref py py-attr docutils literal"><span class="pre">Bits.intle</span></code></a>.</p>
<p>When used as a setter the value must fit into the current length of the <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a>, else a <code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code> will be raised.</p>
</dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.intne">
<code class="descname">intne</code><a class="headerlink" href="#bitstring.BitArray.intne" title="Permalink to this definition">¶</a></dt>
<dd><p>Writable version of <a class="reference internal" href="constbitarray.html#bitstring.Bits.intne" title="bitstring.Bits.intne"><code class="xref py py-attr docutils literal"><span class="pre">Bits.intne</span></code></a>.</p>
<p>When used as a setter the value must fit into the current length of the <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a>, else a <code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code> will be raised.</p>
</dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.float">
<code class="descname">float</code><a class="headerlink" href="#bitstring.BitArray.float" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.floatbe">
<code class="descname">floatbe</code><a class="headerlink" href="#bitstring.BitArray.floatbe" title="Permalink to this definition">¶</a></dt>
<dd><p>Writable version of <a class="reference internal" href="constbitarray.html#bitstring.Bits.float" title="bitstring.Bits.float"><code class="xref py py-attr docutils literal"><span class="pre">Bits.float</span></code></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.floatle">
<code class="descname">floatle</code><a class="headerlink" href="#bitstring.BitArray.floatle" title="Permalink to this definition">¶</a></dt>
<dd><p>Writable version of <a class="reference internal" href="constbitarray.html#bitstring.Bits.floatle" title="bitstring.Bits.floatle"><code class="xref py py-attr docutils literal"><span class="pre">Bits.floatle</span></code></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.floatne">
<code class="descname">floatne</code><a class="headerlink" href="#bitstring.BitArray.floatne" title="Permalink to this definition">¶</a></dt>
<dd><p>Writable version of <a class="reference internal" href="constbitarray.html#bitstring.Bits.floatne" title="bitstring.Bits.floatne"><code class="xref py py-attr docutils literal"><span class="pre">Bits.floatne</span></code></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.oct">
<code class="descname">oct</code><a class="headerlink" href="#bitstring.BitArray.oct" title="Permalink to this definition">¶</a></dt>
<dd><p>Writable version of <a class="reference internal" href="constbitarray.html#bitstring.Bits.oct" title="bitstring.Bits.oct"><code class="xref py py-attr docutils literal"><span class="pre">Bits.oct</span></code></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.se">
<code class="descname">se</code><a class="headerlink" href="#bitstring.BitArray.se" title="Permalink to this definition">¶</a></dt>
<dd><p>Writable version of <a class="reference internal" href="constbitarray.html#bitstring.Bits.se" title="bitstring.Bits.se"><code class="xref py py-attr docutils literal"><span class="pre">Bits.se</span></code></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.ue">
<code class="descname">ue</code><a class="headerlink" href="#bitstring.BitArray.ue" title="Permalink to this definition">¶</a></dt>
<dd><p>Writable version of <a class="reference internal" href="constbitarray.html#bitstring.Bits.uie" title="bitstring.Bits.uie"><code class="xref py py-attr docutils literal"><span class="pre">Bits.uie</span></code></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.sie">
<code class="descname">sie</code><a class="headerlink" href="#bitstring.BitArray.sie" title="Permalink to this definition">¶</a></dt>
<dd><p>Writable version of <a class="reference internal" href="constbitarray.html#bitstring.Bits.sie" title="bitstring.Bits.sie"><code class="xref py py-attr docutils literal"><span class="pre">Bits.sie</span></code></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.uie">
<code class="descname">uie</code><a class="headerlink" href="#bitstring.BitArray.uie" title="Permalink to this definition">¶</a></dt>
<dd><p>Writable version of <a class="reference internal" href="constbitarray.html#bitstring.Bits.ue" title="bitstring.Bits.ue"><code class="xref py py-attr docutils literal"><span class="pre">Bits.ue</span></code></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.uint">
<code class="descname">uint</code><a class="headerlink" href="#bitstring.BitArray.uint" title="Permalink to this definition">¶</a></dt>
<dd><p>Writable version of <a class="reference internal" href="constbitarray.html#bitstring.Bits.uint" title="bitstring.Bits.uint"><code class="xref py py-attr docutils literal"><span class="pre">Bits.uint</span></code></a>.</p>
<p>When used as a setter the value must fit into the current length of the <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a>, else a <code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code> will be raised.</p>
</dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.uintbe">
<code class="descname">uintbe</code><a class="headerlink" href="#bitstring.BitArray.uintbe" title="Permalink to this definition">¶</a></dt>
<dd><p>Writable version of <a class="reference internal" href="constbitarray.html#bitstring.Bits.uintbe" title="bitstring.Bits.uintbe"><code class="xref py py-attr docutils literal"><span class="pre">Bits.uintbe</span></code></a>.</p>
<p>When used as a setter the value must fit into the current length of the <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a>, else a <code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code> will be raised.</p>
</dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.uintle">
<code class="descname">uintle</code><a class="headerlink" href="#bitstring.BitArray.uintle" title="Permalink to this definition">¶</a></dt>
<dd><p>Writable version of <a class="reference internal" href="constbitarray.html#bitstring.Bits.uintle" title="bitstring.Bits.uintle"><code class="xref py py-attr docutils literal"><span class="pre">Bits.uintle</span></code></a>.</p>
<p>When used as a setter the value must fit into the current length of the <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a>, else a <code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code> will be raised.</p>
</dd></dl>
<dl class="attribute">
<dt id="bitstring.BitArray.uintne">
<code class="descname">uintne</code><a class="headerlink" href="#bitstring.BitArray.uintne" title="Permalink to this definition">¶</a></dt>
<dd><p>Writable version of <a class="reference internal" href="constbitarray.html#bitstring.Bits.uintne" title="bitstring.Bits.uintne"><code class="xref py py-attr docutils literal"><span class="pre">Bits.uintne</span></code></a>.</p>
<p>When used as a setter the value must fit into the current length of the <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a>, else a <code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code> will be raised.</p>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.__delitem__">
<code class="descname">__delitem__</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.__delitem__" title="Permalink to this definition">¶</a></dt>
<dd><p><code class="docutils literal"><span class="pre">del</span> <span class="pre">s[start:end:step]</span></code></p>
<p>Deletes the slice specified.</p>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.__iadd__">
<code class="descname">__iadd__</code><span class="sig-paren">(</span><em>bs</em><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.__iadd__" title="Permalink to this definition">¶</a></dt>
<dd><p><code class="docutils literal"><span class="pre">s1</span> <span class="pre">+=</span> <span class="pre">s2</span></code></p>
<p>Appends <em>bs</em> to the current bitstring.</p>
<p>Note that for <a class="reference internal" href="#bitstring.BitArray" title="bitstring.BitArray"><code class="xref py py-class docutils literal"><span class="pre">BitArray</span></code></a> objects this will be an in-place change, whereas for <a class="reference internal" href="constbitarray.html#bitstring.Bits" title="bitstring.Bits"><code class="xref py py-class docutils literal"><span class="pre">Bits</span></code></a> objects using <code class="docutils literal"><span class="pre">+=</span></code> will not call this method - instead a new object will be created (it is equivalent to a copy and an <a class="reference internal" href="constbitarray.html#bitstring.Bits.__add__" title="bitstring.Bits.__add__"><code class="xref py py-meth docutils literal"><span class="pre">__add__</span></code></a>).</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="n">BitArray</span><span class="p">(</span><span class="n">ue</span><span class="o">=</span><span class="mi">423</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span> <span class="o">+=</span> <span class="n">BitArray</span><span class="p">(</span><span class="n">ue</span><span class="o">=</span><span class="mi">12</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="s1">'ue'</span><span class="p">)</span>
<span class="go">423</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="s1">'ue'</span><span class="p">)</span>
<span class="go">12</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.__iand__">
<code class="descname">__iand__</code><span class="sig-paren">(</span><em>bs</em><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.__iand__" title="Permalink to this definition">¶</a></dt>
<dd><p><code class="docutils literal"><span class="pre">s</span> <span class="pre">&=</span> <span class="pre">bs</span></code></p>
<p>In-place bit-wise AND between two bitstrings. If the two bitstrings are not the same length then a <code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code> is raised.</p>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.__ilshift__">
<code class="descname">__ilshift__</code><span class="sig-paren">(</span><em>n</em><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.__ilshift__" title="Permalink to this definition">¶</a></dt>
<dd><p><code class="docutils literal"><span class="pre">s</span> <span class="pre"><<=</span> <span class="pre">n</span></code></p>
<p>Shifts the bits in-place <em>n</em> bits to the left. The <em>n</em> right-most bits will become zeros and bits shifted off the left will be lost.</p>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.__imul__">
<code class="descname">__imul__</code><span class="sig-paren">(</span><em>n</em><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.__imul__" title="Permalink to this definition">¶</a></dt>
<dd><p><code class="docutils literal"><span class="pre">s</span> <span class="pre">*=</span> <span class="pre">n</span></code></p>
<p>In-place concatenation of <em>n</em> copies of the current bitstring.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="n">BitArray</span><span class="p">(</span><span class="s1">'0xbad'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span> <span class="o">*=</span> <span class="mi">3</span>
<span class="gp">>>> </span><span class="n">s</span><span class="o">.</span><span class="n">hex</span>
<span class="go">'badbadbad'</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.__ior__">
<code class="descname">__ior__</code><span class="sig-paren">(</span><em>bs</em><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.__ior__" title="Permalink to this definition">¶</a></dt>
<dd><p><code class="docutils literal"><span class="pre">s</span> <span class="pre">|=</span> <span class="pre">bs</span></code></p>
<p>In-place bit-wise OR between two bitstrings. If the two bitstrings are not the same length then a <code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code> is raised.</p>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.__irshift__">
<code class="descname">__irshift__</code><span class="sig-paren">(</span><em>n</em><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.__irshift__" title="Permalink to this definition">¶</a></dt>
<dd><p><code class="docutils literal"><span class="pre">s</span> <span class="pre">>>=</span> <span class="pre">n</span></code></p>
<p>Shifts the bits in-place <em>n</em> bits to the right. The <em>n</em> left-most bits will become zeros and bits shifted off the right will be lost.</p>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.__ixor__">
<code class="descname">__ixor__</code><span class="sig-paren">(</span><em>bs</em><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.__ixor__" title="Permalink to this definition">¶</a></dt>
<dd><p><code class="docutils literal"><span class="pre">s</span> <span class="pre">^=</span> <span class="pre">bs</span></code></p>
<p>In-place bit-wise XOR between two bitstrings. If the two bitstrings are not the same length then a <code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code> is raised.</p>
</dd></dl>
<dl class="method">
<dt id="bitstring.BitArray.__setitem__">
<code class="descname">__setitem__</code><span class="sig-paren">(</span><em>key</em>, <em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#bitstring.BitArray.__setitem__" title="Permalink to this definition">¶</a></dt>
<dd><p><code class="docutils literal"><span class="pre">s1[start:end:step]</span> <span class="pre">=</span> <span class="pre">s2</span></code></p>
<p>Replaces the slice specified with a new value.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">s</span> <span class="o">=</span> <span class="n">BitArray</span><span class="p">(</span><span class="s1">'0x00000000'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">s</span><span class="p">[::</span><span class="mi">8</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'0xf'</span>
<span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
<span class="go">0x80808080</span>
<span class="gp">>>> </span><span class="n">s</span><span class="p">[</span><span class="o">-</span><span class="mi">12</span><span class="p">:]</span> <span class="o">=</span> <span class="s1">'0xf'</span>
<span class="gp">>>> </span><span class="k">print</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
<span class="go">0x80808f</span>
</pre></div>
</div>
</dd></dl>
</dd></dl>
</div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="constbitstream.html" title="The ConstBitStream class"
>next</a> |</li>
<li class="right" >
<a href="constbitarray.html" title="The Bits class"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">bitstring</a> »</li>
<li class="nav-item nav-item-1"><a href="reference.html" >Reference</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
</div>
</body>
</html>
|