error when porting C code to Python (bitwise manipulation)
Jordan
JordanNealBerg at gmail.com
Thu Jul 10 00:42:58 EDT 2008
I realize I did a pretty bad job of explaining the problem. The
problem is the python version is returning an r that is WAAAAY to big.
Here is an example run through that function in each language:
C:
u starts at 1050
u += 0xe91aaa35;
u is now -384127409
u ^= u >> 16;
u is now -384153771
u += u << 8;
u is now 56728661
u ^= u >> 4;
u is now 56067472
b = (u >> 8) & 0x1ff;
b is now 389
a = (u + (u << 2)) >> 19;
a is now 534
r = a ^ hash_adjust[b];
r is now 6366
Python:
u starts at 1050
u += 0xe91aaa35
u is now 3910839887L
rut roh...
More information about the Python-list
mailing list