I am currently trying to read a single bit from a File in Java.
I read the Data into a byte array and then convert the byte array into a Bitset.
The Problem is that sometimes there are a few bits missing in the converted Bitset.
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.
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());
}
}