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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
- 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