Returns the int value of a six bit substring from the BitSet. - Java java.util

Java examples for java.util:BitSet

Description

Returns the int value of a six bit substring from the BitSet.

Demo Code


//package com.java2s;
import java.util.BitSet;

public class Main {
    /**/*w ww  .ja v a 2 s  . c om*/
     * Returns the int value of a six bit substring from the BitSet.
     * 
     * @param bs
     *          The BitSet
     * @param index
     *          Which set opf six bits to convert (0 based)
     * @return The int value of the six bits of the BitSet from index+0 to index+5
     *         inclusive.
     */
    public static int sixBits2Int(BitSet bs, int index) {
        int temp = 0;

        for (int j = 0; j < 6; j++)
            if (bs.get((index * 6) + j))
                temp |= 1 << j;

        return temp;
    }
}

Related Tutorials