Today we are going to share a Python3 Program to add two numbers without using arithmetic operator. If you are a python beginner and want to start learning the python programming, then keep your close attention in this tutorial as I am going to share a Python3 Program to add two numbers without using arithmetic operator with the output.
To increase your Python knowledge, practice all Python programs, here is a collection of 100+ Python problems with solutions.
Copy the below python program and execute it with the help of python compiler.
def Add(x, y):
# Iterate till there is no carry
while (y != 0):
# carry now contains common
# set bits of x and y
carry = x & y
# Sum of bits of x and y where at
# least one of the bits is not set
x = x ^ y
# Carry is shifted by one so that
# adding it to x gives the required sum
y = carry << 1
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to fr[email protected] Your article will appear on the FreeWebMentor main page and help other developers.