Here you can find the source of powerOf2Log2(int n)
public static int powerOf2Log2(int n)
//package com.java2s; //License from project: Open Source License public class Main { public static int powerOf2Log2(int n) { assert isPowerOf2(n) : n + " is not a power of 2"; for (int i = 0; i < 31; i++) { if ((n & 1) == 1) { return i; }/*from w ww. j ava2 s . c o m*/ n >>= 1; } return 0; } public static boolean isPowerOf2(int n) { return n == 0 || (n > 0 && (n & (n - 1)) == 0); } }