reference https www geeksforgeeks orgpositionofrightmostsetbit take in a positive integer number returns the zerobased index of first set bit in that number from right returns 1 if no set bit found getindexofrightmostsetbit0 1 getindexofrightmostsetbit5 0 getindexofrightmostsetbit36 2 getindexofrightmostsetbit8 3 getindexofrightmostsetbit18 traceback most recent call last valueerror input must be a nonnegative integer getindexofrightmostsetbit test traceback most recent call last valueerror input must be a nonnegative integer getindexofrightmostsetbit1 25 traceback most recent call last valueerror input must be a nonnegative integer finding the index of rightmost set bit has some very peculiar usecases especially in finding missing orand repeating numbers in a list of positive integers reference https www geeksforgeeks org position of rightmost set bit take in a positive integer number returns the zero based index of first set bit in that number from right returns 1 if no set bit found get_index_of_rightmost_set_bit 0 1 get_index_of_rightmost_set_bit 5 0 get_index_of_rightmost_set_bit 36 2 get_index_of_rightmost_set_bit 8 3 get_index_of_rightmost_set_bit 18 traceback most recent call last valueerror input must be a non negative integer get_index_of_rightmost_set_bit test traceback most recent call last valueerror input must be a non negative integer get_index_of_rightmost_set_bit 1 25 traceback most recent call last valueerror input must be a non negative integer finding the index of rightmost set bit has some very peculiar use cases especially in finding missing or and repeating numbers in a list of positive integers
def get_index_of_rightmost_set_bit(number: int) -> int:
    

    if not isinstance(number, int) or number < 0:
        raise ValueError("Input must be a non-negative integer")

    intermediate = number & ~(number - 1)
    index = 0
    while intermediate:
        intermediate >>= 1
        index += 1
    return index - 1


if __name__ == "__main__":
    
    import doctest

    doctest.testmod(verbose=True)