def set_bits(data, value, offset, bits=1):
    """
        Set specified bits in integer

        >>> bin(set_bits(0,0b1010,0,4))
        '0b1010'
        >>> bin(set_bits(0,0b1010,3,4))
        '0b1010000'
    """
    mask = (1 << bits) - 1 << offset
    clear = 65535 ^ mask
    data = data & clear | value << offset & mask
    return data
