public class MyClass {
static int setRightmostUnsetBit(int n) {
if ((n & (n + 1)) == 0)
return n;
return n | (n + 1);
}
public static void main(String args[]) {
int n = 25;
System.out.println(Integer.toBinaryString(n));
System.out.println(Integer.toBinaryString(setRightmostUnsetBit(n)));
}
}
/*
run:
11001
11011
*/