usrbinenv python3 provide the functionality to manipulate a single bit def setbitnumber int position int int return number 1 position def clearbitnumber int position int int return number 1 position def flipbitnumber int position int int return number 1 position def isbitsetnumber int position int bool return number position 1 1 def getbitnumber int position int int return intnumber 1 position 0 if name main import doctest doctest testmod usr bin env python3 provide the functionality to manipulate a single bit set the bit at position to 1 details perform bitwise or for given number and x where x is a number with all the bits zeroes and bit on given position one set_bit 0b1101 1 0b1111 15 set_bit 0b0 5 0b100000 32 set_bit 0b1111 1 0b1111 15 set the bit at position to 0 details perform bitwise and for given number and x where x is a number with all the bits ones and bit on given position zero clear_bit 0b10010 1 0b10000 16 clear_bit 0b0 5 0b0 0 flip the bit at position details perform bitwise xor for given number and x where x is a number with all the bits zeroes and bit on given position one flip_bit 0b101 1 0b111 7 flip_bit 0b101 0 0b100 4 is the bit at position set details shift the bit at position to be the first smallest bit then check if the first bit is set by anding the shifted number with 1 is_bit_set 0b1010 0 false is_bit_set 0b1010 1 true is_bit_set 0b1010 2 false is_bit_set 0b1010 3 true is_bit_set 0b0 17 false get the bit at the given position details perform bitwise and for the given number and x where x is a number with all the bits zeroes and bit on given position one if the result is not equal to 0 then the bit on the given position is 1 else 0 get_bit 0b1010 0 0 get_bit 0b1010 1 1 get_bit 0b1010 2 0 get_bit 0b1010 3 1
def set_bit(number: int, position: int) -> int:
    
    return number | (1 << position)


def clear_bit(number: int, position: int) -> int:
    
    return number & ~(1 << position)


def flip_bit(number: int, position: int) -> int:
    
    return number ^ (1 << position)


def is_bit_set(number: int, position: int) -> bool:
    
    return ((number >> position) & 1) == 1


def get_bit(number: int, position: int) -> int:
    
    return int((number & (1 << position)) != 0)


if __name__ == "__main__":
    import doctest

    doctest.testmod()