def set_bits(store, bit_val, r_position, spread):
    """

    :param store: integer pre-manipulation
    :param bit_val: value of the bits to be set
    :param r_position: zero-based indexing position of the right-most bit impacted by the manipulation
    :param spread: how many bits are to be changed. Note: a spread of zero will result in return equal to input.
    :return: integer with bits set
    """
    spread_store_mask = (-1 << spread + r_position) | (1 << r_position) - 1
    store = store & spread_store_mask
    bit_val = bit_val & ((2**spread) - 1)# resize bit_val to fit in spread
    bit_val = bit_val << r_position
    store = store | bit_val
    return store