I have the following code snippet in C++:
for (int x = -4; x < 5; ++x) printf(\"hex x %d 0x%08X\\n\", x, x);
And its output is >
You need to explicitly restrict the integer to 32-bits:
for x in range(-4,5): print "hex x %d 0x%08X" % (x, x & 0xffffffff)