So my problem is that i have to recursively find the number of bits, that are required to display / save a number e.g. 4(10)=100(2) so 3 bits would be needed. I think i already know how i am supposed to do it, but my code still doesnt work. Here is what i have so far:
public static int l = 1;
public static int countUsedBits(long z) {
if (z == 0) {
return l;
} else {
++l;
return countUsedBits(log, z >>> 1);
}
}
The problem is that the returned number is always 1 off (too big) of the correct number. Thanks for any help in advance!