Given two non-negative integers a and b. The problem is to find the position of the rightmost bit where a carry is generated in the binary addition of a and b.
Input : a = 10, b = 2 Output : 2 (10)10 = (1010)2 (2)10 = (10)2. 1010 + 10 As highlighted, 1st carry bit from the right will be generated at position '2'. Input : a = 10, b = 5 Output : 0 '0' as no carry bit will be generated.
Approach: Following are the steps:
- Calculate num = a & b.
- Find the position of rightmost set bit in num.
- Position of rightmost set bit
- Turn off the rightmost set bit
- Binary representation of a given number
- Find position of the only set bit
- Check if binary representation of a number is palindrome
- 1's and 2's complement of a Binary Number
- Gray to Binary and Binary to Gray conversion
- Length of the Longest Consecutive 1s in Binary Representation
- XOR counts of 0s and 1s in binary representation
- Maximum 0's between two immediate 1's in binary representation
- Efficient method for 2's complement of a binary string
- Check divisibility in a binary stream
- Find longest sequence of 1's in binary representation with one flip
- Convert decimal fraction to binary number
- Check in binary array the number represented by a subarray is odd or even
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.