This problem is pretty annoying in python because python only has arithmetic shift and no logical shift. We can work around this by converting the full 32 bits to hex and stripping leading 0s if we have to.

```
def toHex(self, num):
"""
:type num: int
:rtype: str
"""
if num == 0 : return '0'
result = []
for i in range(8) :
print num
val = num & 15
result.append(str(val) if val < 10 else chr(val - 10 + ord('a')))
num >>= 4
while result[-1] == '0' : result.pop()
return ''.join(result[::-1])
```