Zero-fill shift

Daniel Orner cs993442 at cs.yorku.ca
Tue May 4 14:04:57 EDT 2004


	Hey all,

	I'm trying to port a (relatively) simple encryption algorithm from Java 
code (mainly because the algorithm will be used identically in both 
contexts). However, the code makes extensive use of Java's >>> operator, 
which shifts right and fills in the leftmost bits with zeroes. I've been 
unable to duplicate that effect in Python.
	Apparently, a >>> b is equal to the following:

    if a >= 0: return a >> b
    else: return (a>>b)+(2<<~b)

	However, Python complains when I try to do the left-shift, because ~b 
is often a negative number. Does anyone have a better idea about how I 
should go about doing this?

	Thanks!

--Daniel




More information about the Python-list mailing list