<p>Trying to answer to another post whose solution deals with IP addresses and netmasks, I got stuck with plain bitwise arithmetic.</p>

<p>Is there a standard way, in Python, to carry on bitwise AND, OR, XOR, NOT operations assuming that the inputs are "32 bit" (maybe negative) integers or longs, and that the result must be a long in the range [0, 2**32]?</p>

<p>In other words, I need a working Python counterpart to the C bitwise operations between  unsigned longs.</p>

<p>EDIT: the specific issue is this:</p>

<pre><code>&gt;&gt;&gt; m = 0xFFFFFF00   # netmask 255.255.255.0
&gt;&gt;&gt; ~m
-4294967041L         # wtf?! I want 255
</code></pre>

```
```
from numpy import uint32
```
```