shift operators?

Joshua Muskovitz joshm at
Mon Jan 7 17:09:30 EST 2002

Is there a way to to right shift (>>) in a non-sign-extended way, short of
my evil hack:

def rshift(num, dist):
    if dist == 0:
        return num
        return ( (num >> dist) & (0x7fffffff >> (dist-1) ) )

I found it very annoying that there was no simple unsigned right shift in
Python.  And it made debugging my DES port a nightmare, until I figured out
what was going on.

-- j

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----

More information about the Python-list mailing list