Position of rightmost different bit | Java implementation to find the position of rightmost different bit ; Function to find the position of rightmost set bit in ' n ' return 0 if there is no set bit . ; to handle edge case when n = 0. ; Function to find the position of rightmost different bit in the binary representations of ' m ' and ' n ' ; position of rightmost different bit ; Driver code
class GFG { static int getRightMostSetBit ( int n ) { if ( n == 0 ) return 0 ; return ( int ) ( ( Math . log10 ( n & - n ) ) / Math . log10 ( 2 ) ) + 1 ; } static int posOfRightMostDiffBit ( int m , int n ) { return getRightMostSetBit ( m ^ n ) ; } public static void main ( String arg [ ] ) { int m = 52 , n = 4 ; System . out . print ( " Position ▁ = ▁ " + posOfRightMostDiffBit ( m , n ) ) ; } }