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 7974143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:17:24+00:00 2026-06-04T08:17:24+00:00

I am trying to read a binary file with the following binary configuration 00

  • 0

I am trying to read a binary file with the following binary configuration

00 00 00 1A 79 20 83 DB 44 ...

using the following function

static BitArray getBitArray(string filename)
{
    FILE *fs = fopen(filename.data(),"r");
    fseek (fs , 0 , SEEK_END);
    unsigned long s = ftell (fs);
    rewind (fs);

    unsigned char *buffer = new unsigned char[s+1];

    fread(buffer,1,s,fs);

    BitArray bArray;
    for(int i=0; i<s; i++)
        bArray.add(buffer[i]);

    delete[] buffer;
    fclose(fs);
    return bArray;
}

where BitArray is just my own bit manipulating class. The problem is, for the bin file I mentioned above, it only reads the first three 0s, like this

00 00 00

even though fseek has found the correct file size.

As to why I need that string 0s, is because 00 00 00 1A forms a 32-bit integer, which happened to be small enough to leave three 0x00s.

I suspected that a string of 0x00s in the beginning of a file is recognized as EOF, so i tried padding a char in front of the file, but it didn’t quite work out.

What could be causing this?

  • 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-06-04T08:17:27+00:00Added an answer on June 4, 2026 at 8:17 am

    in windows, 0x1A a.k.a ^Z is the end-of-file character. You have opened the file in text mode rather than binary mode. When you open a file in text mode in windows it will read until end-of-file or the first ^Z character.

    pass "rb" to fopen instead of "r" to open the file in binary mode.

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

Sidebar

Related Questions

I'm trying to read data from a binary file and put it into a
I am trying to read the number of line in a binary file using
I'm trying to store some binary data obtained from read() in my buffer using
i'm trying to read a binary file (for example an executable) into a string,
I'm trying to load binary file using fstream in the following way: #include <iostream>
I'm trying to read a binary file that is in the following format: number
Im trying to read some data from a binary file into a buffer allocated
Using Python (3.1 or 2.6), I'm trying to read data from binary data files
I'm trying to read a binary file with the following code: open(F, <$file) ||
I am trying to read binary data from sys.stdin using Python 2.7 on Windows

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.