Skip to content

Instantly share code, notes, and snippets.

@thmain
Created July 23, 2017 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/3a2bf49c85746f5e11c0ab9da1e17c93 to your computer and use it in GitHub Desktop.
Save thmain/3a2bf49c85746f5e11c0ab9da1e17c93 to your computer and use it in GitHub Desktop.
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