Getting bits of a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HTB
    New Member
    • Aug 2007
    • 13

    Getting bits of a file

    Hi,
    i have a question. How can i get a stream of bits from a file??
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Depends on whats more important to you - the bits or the streaming. The bits may be sourced by ado.net or stream and locates the bits. What type of file? More info please. Thanks.

    Comment

    • HTB
      New Member
      • Aug 2007
      • 13

      #3
      i want to get the bits (from binary file) and store them
      in an array for manipulating, using C#.

      what should i do, please !?

      Comment

      • vanc
        Recognized Expert New Member
        • Mar 2007
        • 211

        #4
        if the file contains all 0 and 1 then you just have to read line by line and with each line, you then read each char.
        e.g.
        while(!stream.E ndOfStream)
        {
        string s = stream.ReadLine ();
        foreach(char c in s)
        arrayOfBit.Add( c);
        }

        cheers.

        Comment

        • HTB
          New Member
          • Aug 2007
          • 13

          #5
          vanc,

          is this the case if i am dealing with an image file !?

          Comment

          • radcaesar
            Recognized Expert Contributor
            • Sep 2006
            • 759

            #6
            Yes, Since its in Binary format.

            Have a look on this,

            FileStream fs = new FileStream(Sour ceLoc, FileMode.Open,F ileAccess.Read) ;

            // Create a byte array of file stream length
            byte[] ImageData = new byte[fs.Length];

            //Read block of bytes from stream into the byte array
            fs.Read(ImageDa ta,0,System.Con vert.ToInt32(fs .Length));

            //Close the File Stream
            fs.Close();

            Comment

            Working...