Convert numbers into binary representation and add them without carry
Given two numbers N and M. The task to convert both the numbers in the binary form then add respective bits of both the binary converted numbers but with a given condition that there is not any carry system in this addition.
Input: N = 37, M = 12 Output: 41 Input: N = 456, M = 854 Output: 670
Approach:

If we don’t consider carry then the binary addition of two bits will be:
1 + 0 = 1 0 + 1 = 1 0 + 0 = 0 1 + 1 = 0 (No carry)
 If you observe clearly you will notice that this is just bitwise XOR of two numbers.
Below is the implementation of the above approach
C++
// C++ program to add two binary // number without carry #include<bits/stdc++.h> using namespace std; // Function returns sum of both // the binary number without // carry int NoCarrySum( int N, int M) { // XOR of N and M return N ^ M; } // Driver code int main() { int N = 37; int M = 12; cout << NoCarrySum(N, M); return 0; } 
Java
// Java program to add two binary // number without carry import java.util.*; class GFG{ // Function returns sum of both // the binary number without // carry static int NoCarrySum( int N, int M) { // XOR of N and M return N ^ M; } // Driver code public static void main(String[] args) { int N = 37 ; int M = 12 ; System.out.print(NoCarrySum(N, M)); } } // This code is contributed by amal kumar choubey 
Python3
# Python3 program to add two binary # number without carry # Function returns sum of both # the binary number without # carry def NoCarrySum(N, M): # XOR of N and M return N ^ M # Driver code N = 37 M = 12 print (NoCarrySum(N, M)) # This code is contributed by sayesha 
C#
// C# program to add two binary // number without carry using System; class GFG{ // Function returns sum of both // the binary number without // carry static int NoCarrySum( int N, int M) { // XOR of N and M return N ^ M; } // Driver code static public void Main(String[] args) { int N = 37; int M = 12; Console.Write(NoCarrySum(N, M)); } } // This code is contributed by RajputJi 
41
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a studentfriendly price.
Recommended Posts:
 1 to n bit numbers with no consecutive 1s in binary representation
 1 to n bit numbers with no consecutive 1s in binary representation.
 Position of rightmost bit with first carry in sum of two binary
 Addition of two numbers without carry
 Convert a given Decimal number to its BCD representation
 Find value of kth bit in binary representation
 XOR counts of 0s and 1s in binary representation
 Binary representation of a given number
 Maximum 0's between two immediate 1's in binary representation
 Largest number with binary representation is m 1's and m1 0's
 Maximum distance between two 1's in Binary representation of N
 Binary representation of previous number
 Next greater number than N with exactly one bit different in binary representation of N
 Check if binary representation of a number is palindrome
 Decimal representation of given binary string is divisible by 20 or not
 Length of the Longest Consecutive 1s in Binary Representation
 Find the nth number whose binary representation is a palindrome
 Check if all the set bits of the binary representation of N are at least K places away
 Decimal representation of given binary string is divisible by 10 or not
 Occurrences of a pattern in binary representation of a number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.