Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Reading Binary Format (QBasic) with C#

$
0
0

I have a binary file with data stored in an old format [Microsoft Binary Format (QBasic)]

The file is configured like this

-----------------------------------------------------
Start Byte | End Byte | Lenght | Description        |
-----------------------------------------------------
    0    |     3    |   4    | date format YYMMDD |
-----------------------------------------------------
    4    |     7    |   4    | Float              |
-----------------------------------------------------
    8    |     11   |   4    | Float              |
-----------------------------------------------------
  \
  \
  \
-----------------------------------------------------
   24    |     27   |   4    | Float              |
----------------------------------------------------- 

The first 4 bytes contain the date and reset all in Float like 34.5

When i read the file using BinaryRead i do not know to convert to date and float

Here is my code
========================================================


        FileStream fs;
        BinaryReader br;

        byte[] buffer = new byte[28];
        int intBuffer = 0;

fs = File.Open("myFile.dat", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
br = new BinaryReader(fs);

            while ((intBuffer = br.Read(buffer, 0, 28)) > 0)
            {
                DateTime date = GetDateOutOfByte(buffer, 0, 3);
                float f1 = GetFloatOutOfByte(buffer, 4, 7);
                float f2 = GetFloatOutOfByte(buffer, 8, 11);
                float f3 = GetFloatOutOfByte(buffer, 12, 15);
                float f4 = GetFloatOutOfByte(buffer, 16, 19);
                float f5 = GetFloatOutOfByte(buffer, 20, 23);
                float f6 = GetFloatOutOfByte(buffer, 24, 27);
            }

-----------------------------
private float GetFloatOutOfByte(byte[] buffer, int Start, int End)
        {
            string temp = "";
            float result =0.0F;
            for (int i = Start; i < End; i++)
            {
                temp += (char)bufferIdea;
            }
            // How to convert the temp to float?

            return result;
        }
------------------------------
private DateTime GetDateOutOfByte(byte[] buffer, int Start, int End)
        {
            string temp = "";
            DateTime result;
            for (int i = Start; i < End; i++)
            {
                temp += (char)bufferIdea;
            }
            // How to convert the temp to Date?

            return result;
        }
------------------------------

Any Help Please


 


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>