• + 6 comments

    Actually we could do the things a bit more simple here.

    Here we totally avoid branching and an extra variable:

    while (n > 0) {
        counter = ++counter * (n%2);
        max = Math.max(counter, max);
        n/=2;
    }