code: public static final long[] getAllPermutations(int bits, int length) {
      long min = allOnes(bits);
      long permutations = CombinatoricUtils.combinations(length, bits);
      long[] retVal = new long[(int) permutations];
  
      long val = min;
      for (int idx = 0; idx < permutations; idx++) {
        retVal[idx] = val;
        val = nextPermutation(val);
      }
      return retVal;
    }
docs: Returns an array containing all permutations of a defined bitset with {@code bits} set and
  maximum length of {@code length}.