Why don't you just open the file in binary mode? this function opens the file in binary mode and returns an array of bytes:
private byte[] GetBinaryFile(filename) { byte[] bytes; using (FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read)) { bytes = new byte[file.Length]; file.Read(bytes, 0, (int)file.Length); } return bytes; }
then convert it to bits:
byte[] bytes = GetBinaryFile("filename.bin"); BitArray bits = new BitArray(bytes);
now the variable bit has the value 0.1 that you wanted.
or you can just do this:
private BitArray GetFileBits(filename) { byte[] bytes; using (FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read)) { bytes = new byte[file.Length]; file.Read(bytes, 0, (int)file.Length); } return new BitArray(bytes); }
source share