Java BitSet to bitSetToUnsignedInt(BitSet b, int startBit, int length)

Here you can find the source of bitSetToUnsignedInt(BitSet b, int startBit, int length)

Description

Convert a BitSet to an unsigned integer.

License

Open Source License

Parameter

Parameter Description
b BitSet to convert.
startBit LSB bit of the integer.
length Number of bits to read.

Return

an unsigned integer number.

Declaration

public static int bitSetToUnsignedInt(BitSet b, int startBit, int length) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.BitSet;

public class Main {
    /**/*from   w  w  w .j a va 2 s. co m*/
     * Convert a BitSet to an unsigned integer.
     *
     * @param b BitSet to convert.
     * @param startBit LSB bit of the integer.
     * @param length Number of bits to read.
     * @return an unsigned integer number.
     */
    public static int bitSetToUnsignedInt(BitSet b, int startBit, int length) {
        int val = 0;
        int bitval = 1;
        for (int i = 0; i < length; i++) {
            if (b.get(startBit + i))
                val += bitval;
            bitval += bitval;
        }

        return val;
    }
}

Related

  1. bitsetToDoubleArray(BitSet bs, int n)
  2. bitsetToIndices(BitSet bits)
  3. bitSetToInt(final BitSet bitSet)
  4. bitSetToLong(BitSet set)
  5. bitSetToMap(Map map, String key, BitSet bits, int length)
  6. bitsToBytes(BitSet ba, int size)
  7. BitsToBytes(BitSet bits)
  8. bitsToHexString(BitSet ba, int size)
  9. BitsToInt(BitSet bits, int length)