//Method 1 int count = 0; while (n) { count++; n >>= 1; } //Method 2 int count = (int)log2(number)+1;