private static int ceilingLog2 ( int n ) { int oa ; int i ; int b ; oa = n ; b = 32 / 2 ; i = 0 ; while ( b != 0 ) { i = ( i << 1 ) ; if ( n >= ( 1 << b ) ) { n /= ( 1 << b ) ; i = i | 1 ; } else { n &= ( 1 << b ) - 1 ; } b /= 2 ; } if ( ( 1 << i ) == oa ) { return i ; } else { return i + 1 ; } }
Calculates the smallest integer value m such that m^2 > = n . The ceiling log2 of n .