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
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…