code: public static final int[] getBitsSet(final long val) {
      long tmp = val;
      int[] retVal = new int[Long.bitCount(val)];
      for (int i = 0; i < retVal.length; i++) {
        retVal[i] = Long.numberOfTrailingZeros(tmp);
        tmp = tmp ^ Long.lowestOneBit(tmp);
      }
      return retVal;
    }
docs: Returns the number of bits set.