Skip to content

Instantly share code, notes, and snippets.

@JamesTheAwesomeDude
Created July 7, 2018 19:07
Show Gist options
  • Save JamesTheAwesomeDude/c969276c352ae9bde7786a91e8b66bbe to your computer and use it in GitHub Desktop.
Save JamesTheAwesomeDude/c969276c352ae9bde7786a91e8b66bbe to your computer and use it in GitHub Desktop.
rotr = lambda v,n=1,s=8: ((v>>n)|(v<<(s-n)))&~(~0<<s)
rotl = lambda v,n=1,s=8: ((v<<n)|(v>>(s-n)))&~(~0<<s)
#rot*(number, number_of_bits_to_shift, size_of_number)
assert rotr(0b11110011,3) \
== 0b01111110
assert rotl(0xDEADBEEF,20,32) \
== 0xEEFDEADB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment