title: BitSet sometimes drops Bits
body: <p>I am currently trying to read a single bit from a File in Java.</p>
  <p>I read the Data into a byte array and then convert the byte array into a Bitset.</p>
  <p>The Problem is that sometimes there are a few bits missing in the converted Bitset.</p>
  <p>In the following Example i have 2 Byte Arrays, each with 25 very similar Bytes. But one is converted into the expected 200 bits and the other one into only 197 bits and i have no idea why.</p>
  <pre><code>import java.nio.ByteBuffer;
  import java.util.BitSet;
  
  public class Main {
      public static void main(String[] args) {
          ByteBuffer cb = ByteBuffer.wrap(new byte[] {(byte)0x18,(byte)0x8C,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,});
          BitSet cBits = BitSet.valueOf(cb);
          System.out.println(cBits.length());
          ByteBuffer db = ByteBuffer.wrap(new byte[] {(byte)0x17,(byte)0x8c,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x18,(byte)0x8c,(byte)0x8c,});
          BitSet dBits = BitSet.valueOf(db);
          System.out.println(dBits.length());
      }
  }
  </code></pre>
  <p><a href="http://jdoodle.com/ia/gf" rel="nofollow noreferrer">Doodle</a></p>