dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: I am read File and I want to get information from each 256 byte and from each 256 byt

  1. #1
    Join Date
    Oct 2006
    Posts
    123

    I am read File and I want to get information from each 256 byte and from each 256 byt

    Hello ,

    I am read File and I want to get information from each 256 byte and from each 256 byte I want to divided each 16 byte in order and get my Info?

    Here's Sample of Converted 256 Byte
    ------------------------------------------
    01 1C 09 0A 0A 0B 1C 09 0A 0A 0C 00 01 00 00 01 01 1C 09 0A 0A 0C 1C 09 0A 0A 0D 80 01 00 00 02 02 1C 09 0A 0A 0D 1C 09 0A 0A 0E 00 02 00 00 03 03 1C 09 0A 0A 0E 1C 09 0A 0A 0F 80 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

    Here's My Logic but I can not do it using code.
    I want to Read All bytes and if Number of Byte equal to 256 I will go to Nested loop to Read 16 byte from previous 256 byte and Get Info

  2. #2
    Join Date
    Oct 2005
    Location
    Seattle, WA U.S.A.
    Posts
    353

    Re: I am read File and I want to get information from each 256 byte and from each 256

    Here's one solution. Perhaps not the one you hoped for, but it might work ...

    Code:
            // ********************************************************************
            private void alternateMethod() {
                byte[] MOAB = new byte[256];
                byte[] smaller = new byte[16];
    
                string filename = @"C:\NYT.txt";
                string spacer = "SPACER   SPACER   SPACER";
                string NYT;
    
                ASCIIEncoding ascii = new ASCIIEncoding();
    
                int bytesRead;
    
                using (FileStream file = new FileStream(filename, FileMode.Open)) {
                    using (BinaryReader reader = new BinaryReader(file))  {
                        bytesRead = reader.Read(MOAB, 0, 256);
                        if (bytesRead == 256) {
                            AddThisItem(spacer);
                            for (int i = 0; i < 16; i++)  {
                                Array.Copy(MOAB, i * 16, smaller, 0, 16);
                                // process the smaller 16-byte segment
                                NYT = ascii.GetString(smaller);
                                AddThisItem(NYT);
                            }// end FOR all 16 segments of MOAB
                        }// if all 256 bytes were read.
                    }// end USING BinaryReader
                }// end USING FileStream
            }// end function 'Form1.alternateMethod'
            // ********************************************************************

    It attempts to read in 256 bytes of data. If the read was successful it writes a spacer to a text box on form1. It then enters a 16-cycle loop where it creates a 16-byte array from the 256-byte block, and processes the 16-byte element (in this case, adds the 16-byte string to a text box on Form1).

    I had an earlier method but when I finished, I realized it processed 16-byte elements "on the fly" (as they were read in), but you requested that all 256 bytes were read in before any processing occurred (hence the need for an alternate method and the 'spacer' - to separate the results from the two different functions).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)