Let's say I have the following bit masks:
1 << 1, // 2
1 << 2, // 4
1 << 3, // 8
1 << 4, // 16
1 << 5, // 32
1 << 6 // 64
I would like to get the 'inverse'.
This does the job:
void foo(int n) {
int c = 1;
while (n/2 >= 2) {
n /= 2;
c++;;
}
println(c);
}
For example, 1 << 4
resulted in 16. If I run foo(16)
it prints 4.
However, I feel like it could be done a lot simpler, but I can't figure out how.
Is it possible?