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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:55:21+00:00 2026-05-31T09:55:21+00:00

I am honestly really confused on reading binary files in C#. I have C++

  • 0

I am honestly really confused on reading binary files in C#.
I have C++ code for reading binary files:

FILE *pFile = fopen(filename, "rb");    
uint n = 1024;
uint readC = 0;
do {
    short* pChunk = new short[n];
    readC = fread(pChunk, sizeof (short), n, pFile);    
} while (readC > 0);

and it reads the following data:

-156, -154, -116, -69, -42, -36, -42, -41, -89, -178, -243, -276, -306,...

I tried convert this code to C# but cannot read such data. Here is code:

using (var reader = new BinaryReader(File.Open(filename, FileMode.Open)))
{
     sbyte[] buffer = new sbyte[1024];                
     for (int i = 0; i < 1024; i++)
     {
         buffer[i] = reader.ReadSByte();
     }                
}

and i get the following data:

100, -1, 102, -1, -116, -1, -69, -1, -42, -1, -36 

How can i get similar data?

  • 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-31T09:55:22+00:00Added an answer on May 31, 2026 at 9:55 am

    A short is not a signed byte, it’s a signed 16 bit value.

     short[] buffer = new short[1024];                
     for (int i = 0; i < 1024; i++) {
         buffer[i] = reader.ReadInt16();
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am honestly really confused on reading binary files in C. My data is
I have this Objective-C code that I found somewhere. Honestly, I don't understand a
Honestly, I don't really know how to begin. I have a live site in
Honestly, now when we have so many javascript features on the frontend I really
I'm working on a security project in Javascript (something I honestly have not used),
I really hope this isn't redundant, but I honestly can't find the answer in
This really is a noobish question, but I honestly don't know how to solve
I'm learning about HTML5, and honestly I can't say I'm really impressed. Semantics are
I'm a beginner but have been working really hard to build this application. Working
I honestly do not know what they are called. I have been unable to

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.