Python bitarray manipulation
<p>I want to remove the least significant 2 bits of every 16-bit integer from a bitarray. They're stored like this:</p>

<pre><code>010101**00**10010101101100**00**10101010.....
</code></pre>

<p>(The zeroes between the asterisks will be removed. There are two of them every 16 bits (ignoring the very first)).</p>

<p>I can simply eliminate them with a regular for loop checking indexes (the 7th and 8th after every 16 bits). </p>

<p>But... is there another more <em>pythonic</em> way to do this? I'm thinking about some slice notation or maybe comprehension lists. Perhaps I could divide every number by 4 and encode every one with 14 bits (if there's a way to do that).</p>

<p>You can clear bits quite easily with masking. If you want to clear bits 8 and 7 you can do it like this:</p>

<pre><code>a = int('10010101101100',2)
mask = ~((1 &lt;&lt; 7) | (1 &lt;&lt; 8))
bin(a&amp;mask)
</code></pre>

<p>more information about masking from <a href="https://wiki.python.org/moin/BitManipulation" rel="nofollow">here!</a></p>

python arrays list bit-manipulation bitarray