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
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)
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
Array Data Structure: Definition, Types, Operations & Advantages Array Data Structure Introduction In this post,…
20 ways to subtract two numbers in Java In this article, we will discuss the…
10 simple ways to add two numbers in Java In this article, we will discuss…
Write a Python program to find the first n prime numbers In this article we…
Python: Calculate Average of odd and even in a list using loops In this post,…
Python: Average of Odd & Even Numbers from User Input In this post, we will…