Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class RightMostSetBit {
public static void findRightMostSetBit(int n){
double position = 1 + Math.log(n & ~(n-1))/Math.log(2);
System.out.println("Right most set bit for " + n + " is : " + Integer.toBinaryString(n & ~(n-1)));
System.out.println("Position: " + position);
}
public static void main(String[] args) {
int n = 1;
findRightMostSetBit(n);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment