error when porting C code to Python (bitwise manipulation)

Jordan JordanNealBerg at gmail.com
Thu Jul 10 10:47:54 CEST 2008


Well, I have figured out something that works:

def findit(u):
    u += 0xe91aaa35
    u1 = ~(0xffffffff - u) ^ u >> 16
    u1 += ((u1 << 8) & 0xffffffff)
    u1 ^= (u1 & 0xffffffff) >> 4
    b  = (u1 >> 8) & 0x1ff
    a  = (u1 + (u1 << 2)  & 0xffffffff) >> 19
    r  = int(a) ^ hash_adjust[int(b)]
    return r


I feel like this cannot possibly be the best way of doing this, but it
does work!!!! haha

If anyone would care to share a more elegant solution, that would be
great :)



More information about the Python-list mailing list