Java - BitSet to integer
<p>So taking the <a href="https://stackoverflow.com/questions/4873952/convert-bitset-to-int">answer</a> with the most upvotes as a base I tried to create a BitSet and set its bits to form the number 478 (111011110) so I did the following:</p>

<pre><code>BitSet set = new BitSet();
set.set(0, true);
set.set(1, true);
set.set(2, true);
set.set(3, false);
set.set(4, true);
set.set(5, true);
set.set(6, true);
set.set(7, true);
set.set(8, false);
System.out.println(bitSetToInt(set));
</code></pre>

<p>with the aid of the following method:</p>

<pre><code>public static int bitSetToInt(BitSet bitSet) {
        int bitInteger = 0;

        for (int i = 0; i &lt; 32; i++){
            if (bitSet.get(i)) {
                bitInteger |= (1 &lt;&lt; i);
            }
        }
        return bitInteger;
    }
</code></pre>

<p>So although I was expecting to get 478 back from this call I am getting 247. Can someone explain me what is going on?</p>