Calculating the biggest number of consecutive ones in a binary number
How about this? (maybe needs some adaption in Java):

int consBits(int x) {
    int consecutiveBits = 0;
    for(;x;consecutiveBits++)
        x &amp;= (x&lt;&lt;1u);

    return consecutiveBits;
}


The idea is to binary &amp; a number with a shifted version of itself. If it is not 0 there is a consecutive sequence of ones. Repeat until the result is 0 and we get the total length of consecutive ones.