cant you use http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#highestOneBit(int)? 
```Integer.highestOneBit(number-1)``` should do the trick without any loop. wdty?