def override_least_significant_bit(integer, bit):
    """Overrides the last bit of an integer with the given one and returns the result"""
    # http://stackoverflow.com/questions/6059454/replace-least-significant-bit-with-bitwise-operations
    integer = (integer & ~1) | bit
    return integer