def turn_on_last_zero(S): 
    """
    Turns on the rightmost 0-bit in word `S`, producing all 1's if none.

    By product, the position of toggled 0-bit is returned.

    Examples
    ========

    When a 0-bit is present:
    >>> S, z = turn_on_last_zero(0b10100111)
    >>> bin(S)
    '0b10101111'
    >>> z
    3

    When a 0-bit is *implicitly* present:
    >>> S, z = turn_on_last_zero(0b11111)
    >>> bin(S)
    '0b111111'
    >>> z
    5
    """
    SS = S | (S + 1)
    z = (SS ^ S).bit_length()-1
    return SS, z