- On
- By
- 0 Comment
- Categories: addition, Calculations
Python Example to sum of two integer using Bitwise operator
Python Example to sum of two integer using Bitwise operator
In this article, we will discuss the concept of the Python Example to sum of two integers using Bitwise operator
In this post, we are going to learn how to write a program to find the sum of two numbers using Bitwise operator in Python programming language
Code to find the addition of two numbers
Addition of two integer using Bitwise operator
The program allows the user to enter two integers and then calculates sum of given numbers using Bitwise operator in Python language
Program 1
#Python program to sum of two numbers #using bitwise operator a=int(input("Enter the number for a: ")) b=int(input("Enter the number for b: ")) #ask input from the user while(b != 0): #calculate sum of two integer using bitwise operator c=a&b #and operator a=a^b #Xor operator b=c<<1 print("Sum of two numbers",a) #display output on the screen
When the above code is executed, it produces the following result
Enter the number for a: 130 Enter the number for b: 220 ('Sum of two numbers', 350)
Sum oft two integer using Bitwise operator – using function
The program allows the user to enter two integers and then calculates sum of given numbers using Bitwise operator in Python language
Program 2
#Python program to sum of two numbers #using bitwise operator a=int(input("Enter the number for a: ")) b=int(input("Enter the number for b: ")) #ask input from the user def add(a,b):#function definition while(b != 0): #calculate sum of two integer using bitwise operator c=a&b #and operator a=a^b #Xor operator b=c<<1 return a print("Sum of two numbers",add(a,b)) #display output on the screen
When the above code is executed, it produces the following result
Enter the number for a: 123 Enter the number for b: 234 ('Sum of two numbers', 357)
Suggested for you
if statements in Python language
Similar post
Subtract two numbers in Python language
Subtract two numbers using function in Python language
Find sum of two numbers in Python Language
Find sum of two numbers in Python using recursion
Find sum of two numbers in Python without Arithmetic operator
Find sum of natural numbers in Python language
Find sum of natural numbers in Python language using recursion