Skip to content

Instantly share code, notes, and snippets.

@thmain
Created July 30, 2017 20:28
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/2236ffff8d97e6cacbeb8fadb242efdc to your computer and use it in GitHub Desktop.
Save thmain/2236ffff8d97e6cacbeb8fadb242efdc to your computer and use it in GitHub Desktop.
public class RightMostUnsetBit {
public static double getRightMostUnsetBit(int n){
if(n==1)
return -1;
return Math.log(~n & (n+1))/Math.log(2);
}
public static void main(String[] args) {
int n = 11;
System.out.println("Right most Unset bit :" + getRightMostUnsetBit(n));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment