def apply_bitshift_scale(x, bitshift, do_round=True):
    """ applies bitshift scale to the vector x

    Parameters:
    - x: np.array(dtype=int), input array
    - bitshift: int: bitshift to the right
    - do_round: add the rounding factor if this is enabled

    Returns: np.array(dtype=int), scaled vector
    """

    assert bitshift >= 0

    if do_round and bitshift > 0:
        #x += np.sign(x) * (1 << (bitshift - 1))
        x += (1 << (bitshift - 1))

    # check if an overflow is happending
    if x.min() < -(1 << 31) or x.max() > ((1 << 31) - 1):
        raise OverflowError()

    x = x >> bitshift

    return x