Hi Java Coders,

For the fun of it, I've made a simple Java solution to the Bits TopCoder Challenge.

The solution simply counts the number of times you can strip off a bit from the right until you reach zero.

The signless bit-shift operator '>>>' is used to make sure that 0 bits are shifted in from the left.


Is there a simpler solution to this challenge without iteration?


public class Bits
{
public int minBits(int n) {
int bitCount= 0;
while (n != 0) {
bitCount++;
n= n >>> 1;
}
return bitCount;
}
}


Kind regards,
Kim Dam Petersen