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

  • Home
  • SEARCH
  • 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 6819605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:19:35+00:00 2026-05-26T21:19:35+00:00

I have a binary file and documentation of the format the information is stored

  • 0

I have a binary file and documentation of the format the information is stored in. I’m trying to write a simple program using c++ that pulls a specific piece of information from the file but I’m missing something since the output isn’t what I expect.

The documentation is as follows:

Half-word   Field Name          Type    Units   Range       Precision
10          Block Divider       INT*2   N/A     -1          N/A
11-12       Latitude            INT*4   Degrees -90 to +90  0.001

There are other items in the file obviously but for this case I’m just trying to get the Latitude value.

My code is:

#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char* argv[])
{
  char* dataFileLocation = "testfile.bin";

  ifstream dataFile(dataFileLocation, ios::in | ios::binary);

  if(dataFile.is_open())
  {
    char* buffer = new char[32768];
    dataFile.seekg(10, ios::beg);
    dataFile.read(buffer, 4);
    dataFile.close();

    cout << "value is << (int)(buffer[0] & 255);
  }
}

The result of which is “value is 226” which is not in the allowed range.

I’m quite new to this and here’s what my intentions where when writing the above code:

  1. Open file in binary mode
  2. Seek to the 11th byte from the start of the file
  3. Read in 4 bytes from that point
  4. Close the file
  5. Output those 4 bytes as an integer.

If someone could point out where I’m going wrong I’d sure appreciate it. I don’t really understand the (buffer[0] & 255) part (took that from some example code) so layman’s terms for that would be greatly appreciated.

Hex Dump of the first 100 bytes:

testfile.bin  98,402 bytes   11/16/2011   9:01:52
          -0 -1 -2 -3  -4 -5 -6 -7  -8 -9 -A -B  -C -D -E -F

00000000- 00 5F 3B BF  00 00 C4 17  00 00 00 E2  2E E0 00 00 [._;.............]
00000001- 00 03 FF FF  00 00 94 70  FF FE 81 30  00 00 00 5F [.......p...0..._]
00000002- 00 02 00 00  00 00 00 00  3B BF 00 00  C4 17 3B BF [........;.....;.]
00000003- 00 00 C4 17  00 00 00 00  00 00 00 00  80 02 00 00 [................]
00000004- 00 05 00 0A  00 0F 00 14  00 19 00 1E  00 23 00 28 [.............#.(]
00000005- 00 2D 00 32  00 37 00 3C  00 41 00 46  00 00 00 00 [.-.2.7.<.A.F....]
00000006- 00 00 00 00                                        [....            ]
  • 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. Editorial Team
    Editorial Team
    2026-05-26T21:19:35+00:00Added an answer on May 26, 2026 at 9:19 pm

    Since the documentation lists the field as an integer but shows the precision to be 0.001, I would assume that the actual value is the stored value multiplied by 0.001. The integer range would be -90000 to 90000.

    The 4 bytes must be combined into a single integer. There are two ways to do this, big endian and little endian, and which you need depends on the machine that wrote the file. x86 PCs for example are little endian.

    int little_endian = buffer[0] | buffer[1]<<8 | buffer[2]<<16 | buffer[3]<<24;
    int big_endian    = buffer[0]<<24 | buffer[1]<<16 | buffer[2]<<8 | buffer[3];
    

    The &255 is used to remove the sign extension that occurs when you convert a signed char to a signed integer. Use unsigned char instead and you probably won’t need it.

    Edit: I think “half-word” refers to 2 bytes, so you’ll need to skip 20 bytes instead of 10.

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

Sidebar

Related Questions

I have a binary file that I have to parse and I'm using Python.
I have a binary file to which I'm trying to write however I dont
I have a binary file that is really a stack of files, the format
I have a binary file - Windows static library (*.lib). Is there a simple
I have binary data in a file that I can read into a byte
I have a binary file. There are 2288*2288 longitude float values stored in top
Suppose we have a binary file, that contains 32 bit numbers. Each 32bit number
I have one binary file which I have created. In it, data is stored
I have a binary file that I would like to regex search/replace hex bytes
I have a binary file to which I want to append a chunk of

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.