generalize rank to countBits