signed to unsigned

Brad Tilley kj4eit at
Fri Feb 17 19:51:42 CET 2012

In C or C++, I can do this for integer conversion:

unsigned int j = -327681234; // Notice this is signed.

j will equal 3967286062. I thought with Python that I could use struct
to pack the signed int as an unsigned int, but that fails:

>>> x = struct.pack("<I", -327681234)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
struct.error: integer out of range for 'I' format code

Is there an easy way in Python to do the same conversion that C or C++
code does? Thanks for any advice.

More information about the Python-list mailing list