code: public static int cardinality(long[] bits) {
      int card = 0;
      for (int i = bits.length - 1; i >= 0; i--) {
        long a = bits[i];
        if (a == 0)
          continue;
        if (a == -1) {
          card += 64;
          continue;
        }
        // Successively collapse alternating bit groups into a sum.
        a = ((a >> 1) & 0x5555555555555555L) + (a & 0x5555555555555555L);
        a = ((a >> 2) & 0x3333333333333333L) + (a & 0x3333333333333333L);
        int b = (int) ((a >>> 32) + a);
        b = ((b >> 4) & 0x0f0f0f0f) + (b & 0x0f0f0f0f);
        b = ((b >> 8) & 0x00ff00ff) + (b & 0x00ff00ff);
        card += ((b >> 16) & 0x0000ffff) + (b & 0x0000ffff);
      }
      return card;
    }
docs: Checks the number of bits set to 1.
  
  @param bits - bitset
  @return the number of bits set to 1