def _rot(x, shift_amount, length):
    """Rotate x shift_amount bits to the left, considering the   string of bits is length bits long"""
    shift_amount = shift_amount % length
    return ((x >> length - shift_amount) + (x << shift_amount)) % (1 << length)
