fundamental bit operation getbitnum i get an exact bit at specific index setbitnum i set a bit at specific index clearbitnum i clear a bit at specific index updatebitnum i bit update a bit at specific index this function shifts 1 over by i bits creating a value being like 0001000 by performing an and with num we clear all bits other than the bit at bit i finally we compare that to 0 this function shifts 1 over by i bits creating a value being like 0001000 by performing an or with num only value at bit i will change this method operates in almost the reverse of setbit to set the ith bit to value we first clear the bit at position i by using a mask then we shift the intended value finally we or these two numbers this function shifts 1 over by i bits creating a value being like 0001000 by performing an and with num we clear all bits other than the bit at bit i finally we compare that to 0 this function shifts 1 over by i bits creating a value being like 0001000 by performing an or with num only value at bit i will change this method operates in almost the reverse of set_bit to set the ith bit to value we first clear the bit at position i by using a mask then we shift the intended value finally we or these two numbers
def get_bit(num, i):
    return (num & (1 << i)) != 0


def set_bit(num, i):
    return num | (1 << i)


def clear_bit(num, i):
    mask = ~(1 << i)
    return num & mask


def update_bit(num, i, bit):
    mask = ~(1 << i)
    return (num & mask) | (bit << i)