Position of rightmost set bit | Java program to find the first rightmost set bit using XOR operator ; function to find the rightmost set bit ; Position variable initialize with 1 m variable is used to check the set bit ; left shift ; Driver Code ; function call
class GFG { static int PositionRightmostSetbit ( int n ) { int position = 1 ; int m = 1 ; while ( ( n & m ) == 0 ) { m = m << 1 ; position ++ ; } return position ; } public static void main ( String [ ] args ) { int n = 16 ; System . out . println ( PositionRightmostSetbit ( n ) ) ; } }