Skip to content

Instantly share code, notes, and snippets.

@scragg0x
Created February 4, 2013 21:52
Show Gist options
  • Save scragg0x/4710045 to your computer and use it in GitHub Desktop.
Save scragg0x/4710045 to your computer and use it in GitHub Desktop.
Python rotate bits to the right
def rotr(x, n=1, bits=8):
while True:
x = ((x & 1) << bits-1 | x >> 1)
n -= 1
if not n:
break
return x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment