Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 66397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:05:49+00:00 2026-05-10T19:05:49+00:00

I am reading a binary log file produced by a piece of equipment. I

  • 0

I am reading a binary log file produced by a piece of equipment.

I have the data in a byte[].

If I need to read two bytes to create a short I can do something like this:

short value = (short)(byte[1] << 8); value += byte[2]; 

Now I know the value is the correct for valid data.

How would I know if the file was messed up and lets say the values FF FF were in those two places in the byte array?

When I look at the resultant value of converting FF FF to a short, I get a -1.

Is this a normal value for FF FF?, or did the computer just hit some kind of short bound and roll over with invalid data?

For my purposes all of theses numbers are going to be positive. If FF FF is actually a short -1, then I just need to validate that all my results are postitive.

Thank you,
Keith

BTW, I am also reading other number data types. I’ll show them here just because. The Read function is the basic part of reading from the byte[]. All the other data type reads use the basic Read() function.

    public byte Read()     {         //advance position and then return byte at position           byte returnValue;         if (_CurrentPosition < _count - 1)         {             returnValue= _array[_offset + ++_CurrentPosition];             return returnValue;         }         else             throw new System.IO.EndOfStreamException                    ('Cannot Read Array, at end of stream.');      }       public float ReadFloat()     {         byte[] floatTemp = new byte[4];         for (int i = 3; i >= 0; i--)         {             floatTemp[i] = Read();         }          float returnValue = System.BitConverter.ToSingle             (floatTemp, 0);          if (float.IsNaN(returnValue))         {             throw new Execption('Not a Number');             }         return returnValue;     }       public short ReadInt16()     {         short returnValue = (short)(Read() << 8);         returnValue += Read();         return returnValue;     }      public int ReadInt32()     {         int returnValue = Read() << 24;         returnValue += Read() << 16;         returnValue += Read() << 8;         returnValue += Read();         return returnValue;     } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T19:05:49+00:00Added an answer on May 10, 2026 at 7:05 pm

    0xffff (all bits equal to 1) is -1 for signed shorts, yes. Read up on Two’s complement to learn more about the details. You can switch to a larger datatype, or (as suggested by Grzenio) just use an unsigned type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having following issue with reading binary file in C. I have read
i am reading the bytes from binary file and now i have to get
I have to read a binary file data into a C# winform application. The
I have a binary log file with streaming data from a sensor (Int16). Every
I have to read data from a binary file like S/W version,vendor etc. i
Hi everyone i have an issue while reading binary data from a binary file
I'm reading from a binary data file which is written by invoking the following
I'm reading from a binary file and want to convert the bytes to US
I have a very strange problem when reading a binary file. void metaDataProcess(FILE *f){
I have to read a binary file in python. This is first written by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.