Dear sir,
i am very new to c# and i request you to... please look into the problem
The following is the code(please see the code below:) which i uses to open the binary file,currently it works fine ,but now the problem is that 2 bytes are read in simultaneously and is being converted into an integer,but i need to read the data from the file in bits and finally convert 8 bits into binary numbers and then to decimal numbers? could you be able to give me some advice to read the file bit by bit ? is it ok if i read all the bytes into a an array and then try to convert it into a bit array?
with regards,
tom.
-
using System;
-
using System.IO;
-
using System.Collections;
-
-
-
class Program
-
{
-
static void Main()
-
{
-
R();
-
}
-
-
static void R()
-
{
-
// 1.
-
using (BinaryReader b = new BinaryReader(File.Open("file.bin", FileMode.Open)))
-
{
-
// 2.
-
// Position and length variables.
-
int pos = 0;
-
// 2A.
-
// Use BaseStream.
-
int length = (int)b.BaseStream.Length;
-
while (pos < length)
-
{
-
// 3.
-
// Read integer.
-
int v = b.ReadInt32();
-
Console.WriteLine(v);
-
-
// 4.
-
// Advance our position variable.
-
pos += sizeof(int);
-
-
// 5.
-
// Seek to our required position.(int pos1 had to be found out )
-
//int pos1 = 0;
-
//b.BaseStream.Seek(pos1, SeekOrigin.Begin);
-
-
// 6.
-
// Read the next 2000 bytes or required number of bytes int the byte array(int required had to be found out ).
-
//int required = 20000;
-
//byte[] by = b.ReadBytes(required);
-
-
-
-
-
-
-
-
//.8 convert to bit array
-
//BitArray myBits = new BitArray(by);
-
byte[] value = { 0x11 };
-
BitArray myBits = new BitArray(value);
-
-
-
}
-
-
Console.ReadLine();
-
}
-
}
-
}
-
----------------------------------------------------------------------------------------------------------------------------------
and the following is the data which i gets when i try to open this file with visual studio:
S€DŠ4}]ݝ܍MŒM[m4]\|LLŒ|Œ\L,ϼн=]|ܾ˜\qO-<< Kټƻ˯+•€Kj[{TONU^{o‹{{Œ몼ǽŒ9Œh<™ͬ]$
9*]}-œm]ݲݪ*š]‰]€ֽ]
>*\Œˬ"‡ǬkŬK|#̻˯+•~iݝ ݝmݽmܲˆV=5mLL|μŒ Ϭ