2.3 -> 2.4: long int too large to convert to int
Grant Edwards
grante at visi.com
Thu Sep 15 21:33:52 EDT 2005
On 2005-09-15, chrisperkins99 at gmail.com <chrisperkins99 at gmail.com> wrote:
>> fcntl.ioctl(self.dev.fileno(),0xc0047a80,struct.pack("HBB",0x1c,0x00,0x00))
>>
>> I get an OverflowError: long int too large to convert to int
> You could sort-of fake it like this,
>
> def unsigned(val):
> return struct.unpack('i', struct.pack('I', val))[0]
>
> fcntl.ioctl(self.dev.fileno(), unsigned(0xc0047a80), ...)
I rather like this
if i & 0x8000000:
i = -((i^0xffffffff)+1)
As long as I'm obfscating the code, who can resist some bitwise
operations. Of course it'll break on machines that don't use
2's compliment, but that's just iceing on the cake.
--
Grant Edwards grante Yow! I am having FUN... I
at wonder if it's NET FUN or
visi.com GROSS FUN?
More information about the Python-list
mailing list