BitSet To Int - Java java.util

Java examples for java.util:BitSet

Description

BitSet To Int

Demo Code


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

public class Main {
    public static int bitSetToInt(BitSet bitSet) {
        int result = 0;
        for (int i = 0; i < bitSet.length(); i++) {
            if (bitSet.get(i)) {
                result |= (1 << i);
            }/*from ww w.jav a 2s . co  m*/
        }
        result &= Integer.MAX_VALUE;
        return result;
    }
}

Related Tutorials