calculates the sum of two nonnegative integers using bitwise operators wikipedia explanation https en wikipedia orgwikibinarynumber bitwiseadditionrecursive4 5 9 bitwiseadditionrecursive8 9 17 bitwiseadditionrecursive0 4 4 bitwiseadditionrecursive4 5 9 traceback most recent call last typeerror both arguments must be integers bitwiseadditionrecursive 4 9 traceback most recent call last typeerror both arguments must be integers bitwiseadditionrecursive 4 5 9 traceback most recent call last typeerror both arguments must be integers bitwiseadditionrecursive1 9 traceback most recent call last valueerror both arguments must be nonnegative bitwiseadditionrecursive1 9 traceback most recent call last valueerror both arguments must be nonnegative bitwise_addition_recursive 4 5 9 bitwise_addition_recursive 8 9 17 bitwise_addition_recursive 0 4 4 bitwise_addition_recursive 4 5 9 traceback most recent call last typeerror both arguments must be integers bitwise_addition_recursive 4 9 traceback most recent call last typeerror both arguments must be integers bitwise_addition_recursive 4 5 9 traceback most recent call last typeerror both arguments must be integers bitwise_addition_recursive 1 9 traceback most recent call last valueerror both arguments must be non negative bitwise_addition_recursive 1 9 traceback most recent call last valueerror both arguments must be non negative
def bitwise_addition_recursive(number: int, other_number: int) -> int:
    

    if not isinstance(number, int) or not isinstance(other_number, int):
        raise TypeError("Both arguments MUST be integers!")

    if number < 0 or other_number < 0:
        raise ValueError("Both arguments MUST be non-negative!")

    bitwise_sum = number ^ other_number
    carry = number & other_number

    if carry == 0:
        return bitwise_sum

    return bitwise_addition_recursive(bitwise_sum, carry << 1)


if __name__ == "__main__":
    import doctest

    doctest.testmod()