Position of rightmost bit with first carry in sum of two binary | Java 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 code
class GFG { static int posOfRightmostSetBit ( int n ) { return ( int ) ( Math . log ( n & - n ) / Math . log ( 2 ) ) + 1 ; } static int posOfCarryBit ( int a , int b ) { return posOfRightmostSetBit ( a & b ) ; } public static void main ( String [ ] args ) { int a = 10 , b = 2 ; System . out . print ( posOfCarryBit ( a , b ) ) ; } }