Last active
March 30, 2016 14:52
-
-
Save JanBednarik/9d4c428213f615845bb7 to your computer and use it in GitHub Desktop.
Bits rotation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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