Zero-fill shift
Daniel Orner
cs993442 at cs.yorku.ca
Wed May 5 11:44:08 EDT 2004
Great, this works. 8-) Unfortunately, I've run into another problem. In
the Java algorithm, two integers are added. This often results in an
overflow and a negative number, which is the desired result. However, I
can't seem to duplicate that in Python, as adding two integers that are
too large just results in a long (and using the int() method doesn't
work). I've tried various solutions, but haven't come up with something
that duplicates this behavior exactly.
For reference, here's the Java code I'm trying to duplicate:
while(n-- > 0)
{ sum += delta;
y += (z << 4)+a ^ z + sum ^ (z >>> 5) + b;
z += (y << 4)+c ^ y + sum ^ (y >>> 5) + d;
}
with the following initial values:
y = 1751477356
z = 1864398703
a = 2002870900
b = 858797621
c = 1751607922
d = 875968626
sum = 0
delta = 0x9E3779B9
n = 32
Any help would be greatly appreciated. ^^; Thanks!
--Daniel
> def srl(a, b):
> return (a & 0xFFFFFFFFL) >> b
>
> "a & 0xFFFFFFFFL" behaves as if you had written "(unsigned int) a" in C.
More information about the Python-list
mailing list