<p>Say I have the classic 4-byte signed integer, and I want something like</p>
<pre><code>print hex(-1)
</code></pre>
<p>to give me something like</p>
<blockquote>
<p>0xffffffff</p>
</blockquote>
<p>In reality, the above gives me <code>-0x1</code>. I'm dawdling about in some lower level language, and python commandline is quick n easy.</p>
<p>So.. is there a way to do it?</p>

This will do the trick:
```
```
>>> print(hex (-1 & 0xffffffff))
0xffffffff
```
```
or, a variant that always returns fixed size (there may well be a better way to do this):
```
```
>>> def hex3(n):
...     return "0x%s"%("00000000%s"%(hex(n&0xffffffff)[2:-1]))[-8:]
...
>>> print hex3(-1)
0xffffffff
>>> print hex3(17)
0x00000011
```
```
Or, avoiding the hex() altogether, thanks to Ignacio and bobince:
```
```
def hex2(n):
    return "0x%x"%(n&0xffffffff)

def hex3(n):
    return "0x%s"%("00000000%x"%(n&0xffffffff))[-8:]
```
```