예제 #1
0
def create_and_shift_ones(bit_string, i):
    """create bit array of value 1 and then shift it to the left i times. """

    str_length = len(bit_string)
    if i > (str_length - 2):  # deducting 2 for the '0b' of every binary string
        raise Exception('Shifting more than the length of the string')
    one = BitArray('0b' + '0' * (str_length - 1) + bin(1)[2:])  # create a bitarray of ones of that length
    return one.__ilshift__(i)  # shift the binary representation of 1, i times.