Position of rightmost bit with first carry in sum of two binary | C ++ implementation to find the position of rightmost bit where a carry is generated first ; function to find the position of rightmost set bit in ' n ' ; function to find the position of rightmost bit where a carry is generated first ; Driver program to test above
#include <bits/stdc++.h> NEW_LINE using namespace std ; typedef unsigned long long int ull ; unsigned int posOfRightmostSetBit ( ull n ) { return log2 ( n & - n ) + 1 ; } unsigned int posOfCarryBit ( ull a , ull b ) { return posOfRightmostSetBit ( a & b ) ; } int main ( ) { ull a = 10 , b = 2 ; cout << posOfCarryBit ( a , b ) ; return 0 ; }