Java BitSet to bitsetToIndices(BitSet bits)

Here you can find the source of bitsetToIndices(BitSet bits)

Description

Returns a newly constructed array containing the indices of the non-zero bits.

License

Apache License

Declaration

public static int[] bitsetToIndices(BitSet bits) 

Method Source Code

//package com.java2s;
/*******************************************************************************
*   Copyright 2014 Analog Devices, Inc.//from   w w w .ja v  a 2  s. c om
*
*   Licensed under the Apache License, Version 2.0 (the "License");
*   you may not use this file except in compliance with the License.
*   You may obtain a copy of the License at
*
*       http://www.apache.org/licenses/LICENSE-2.0
*
*   Unless required by applicable law or agreed to in writing, software
*   distributed under the License is distributed on an "AS IS" BASIS,
*   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*   See the License for the specific language governing permissions and
*   limitations under the License.
********************************************************************************/

import java.util.BitSet;

public class Main {
    /**
     * Returns a newly constructed array containing the indices of the non-zero bits.
     * @since 0.07
     * @see #bitsetFromIndices
     */
    public static int[] bitsetToIndices(BitSet bits) {
        final int[] indices = new int[bits.cardinality()];
        for (int i = 0, index = -1, end = indices.length; i < end; ++i) {
            index = bits.nextSetBit(++index);
            indices[i] = index;
        }
        return indices;
    }
}

Related

  1. bitSet2byte(BitSet b, int bytes)
  2. bitset2bytes(BitSet bits, byte[] bytes)
  3. bitSet2extendedByte(BitSet b)
  4. bitSet2Int(BitSet bs)
  5. bitsetToDoubleArray(BitSet bs, int n)
  6. bitSetToInt(final BitSet bitSet)
  7. bitSetToLong(BitSet set)
  8. bitSetToMap(Map map, String key, BitSet bits, int length)
  9. bitSetToUnsignedInt(BitSet b, int startBit, int length)