Created
July 30, 2017 20:28
-
-
Save thmain/2236ffff8d97e6cacbeb8fadb242efdc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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