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  w ww.  jav a  2 s. c  o m
        }
        result &= Integer.MAX_VALUE;
        return result;
    }
}

Related Tutorials