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 a "reverse".
This task:
void foo(int n) {
int c = 1;
while (n/2 >= 2) {
n /= 2;
c++;;
}
println(c);
}
For example, it 1 << 4led to 16. If I started foo(16), it prints 4. However, I feel that it can be done much easier, but I can’t figure out how to do it.
Is it possible?
source
share