Skip to content

Instantly share code, notes, and snippets.

@JanBednarik
Last active March 30, 2016 14:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JanBednarik/9d4c428213f615845bb7 to your computer and use it in GitHub Desktop.
Save JanBednarik/9d4c428213f615845bb7 to your computer and use it in GitHub Desktop.
Bits rotation
def rotate_left(byte):
"""
Rotate bits left.
"""
bit = byte & 0x80
byte <<= 1
if(bit):
byte |= 0x01
byte &= 0xFF
return byte
def rotate_right(byte):
"""
Rotate bits right.
"""
byte &= 0xFF
bit = byte & 0x01
byte >>= 1
if(bit):
byte |= 0x80
return byte
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment