unsigned ints and operator.rshift

Matt Gerrans mgerrans at mindspring.com
Mon Jul 22 11:24:32 EDT 2002


I'm sure there's a better way, but in the mean time, here is a shamelessly
cheesy method:

def rShift( i, n ):
   leftbit = 0x80000000
   if i & leftbit:
      return ((i& ~leftbit)>>n)|(0x40000000 >> n-1)
   return i >> n

(this is won't work so well on platforms that have 64-bit ints, either)





More information about the Python-list mailing list