error when porting C code to Python (bitwise manipulation)

Peter Otten __peter__ at web.de
Thu Jul 10 08:37:01 CEST 2008


Jordan wrote:

> C:
> 
> u starts at 1050
> 
> u += 0xe91aaa35;
> 
> u is now -384127409

Hm, a negative unsigned...

> Python:
> 
>    u starts at 1050
> 
>    u += 0xe91aaa35
> 
>    u is now  3910839887L

Seriously, masking off the leading ones is the way to go:

>>> -384127409 & 0xffffffff == 3910839887 & 0xffffffff
True

Peter



More information about the Python-list mailing list