You want to know how many bits are necessary to represent an int? Then there are easier solutions such as:
int bitsNeededFor(int i) {
int bits = 0;
while (i > 0) {
bits++;
i /= 2;
}
return bits;
}
On second thought, the following is faster and easier to understand:
int bitsNeededFor(int i) {
return 32 - Integer.numberOfLeadingZeros(i);
}