Checking if a number is power of 2 or not
There's actually a bit hack for this :

private static boolean isPowerOfTwo(int number) {

    return number &gt; 0 &amp;&amp; ((number &amp; (number - 1)) == 0);

}


(ref : Bit Twiddling hacks)

This exploits the fact, that in binary notation a power of two is a 1 followed by a number of 0's, and the number just below is all 1's equal to that number of 0's :

  100000000 // number
&amp; 011111111 // number - 1
-----------
  000000000