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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:29:09+00:00 2026-05-10T17:29:09+00:00

System.IO.BinaryReader reads values in a little-endian format. I have a C# application connecting to

  • 0

System.IO.BinaryReader reads values in a little-endian format.

I have a C# application connecting to a proprietary networking library on the server side. The server-side sends everything down in network byte order, as one would expect, but I find that dealing with this on the client side is awkward, particularly for unsigned values.

UInt32 length = (UInt32)IPAddress.NetworkToHostOrder(reader.ReadInt32()); 

is the only way I’ve come up with to get a correct unsigned value out of the stream, but this seems both awkward and ugly, and I have yet to test if that’s just going to clip off high-order values so that I have to do fun BitConverter stuff.

Is there some way I’m missing short of writing a wrapper around the whole thing to avoid these ugly conversions on every read? It seems like there should be an endian-ness option on the reader to make things like this simpler, but I haven’t come across anything.

  • 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-10T17:29:09+00:00Added an answer on May 10, 2026 at 5:29 pm

    There is no built-in converter. Here’s my wrapper (as you can see, I only implemented the functionality I needed but the structure is pretty easy to change to your liking):

    /// <summary> /// Utilities for reading big-endian files /// </summary> public class BigEndianReader {     public BigEndianReader(BinaryReader baseReader)     {         mBaseReader = baseReader;     }      public short ReadInt16()     {         return BitConverter.ToInt16(ReadBigEndianBytes(2), 0);     }      public ushort ReadUInt16()     {         return BitConverter.ToUInt16(ReadBigEndianBytes(2), 0);     }      public uint ReadUInt32()     {         return BitConverter.ToUInt32(ReadBigEndianBytes(4), 0);     }      public byte[] ReadBigEndianBytes(int count)     {         byte[] bytes = new byte[count];         for (int i = count - 1; i >= 0; i--)             bytes[i] = mBaseReader.ReadByte();          return bytes;     }      public byte[] ReadBytes(int count)     {         return mBaseReader.ReadBytes(count);     }      public void Close()     {         mBaseReader.Close();     }      public Stream BaseStream     {         get { return mBaseReader.BaseStream;  }     }      private BinaryReader mBaseReader; } 

    Basically, ReadBigEndianBytes does the grunt work, and this is passed to a BitConverter. There will be a definite problem if you read a large number of bytes since this will cause a large memory allocation.

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

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I would use the java.awt.SystemTray in Java SE 6. It's… May 11, 2026 at 11:12 am
  • added an answer It depends on how you are giving your event handler… May 11, 2026 at 11:12 am
  • added an answer If the installer, which spawns the program, is running under… May 11, 2026 at 11:12 am

Related Questions

System.IO.BinaryReader reads values in a little-endian format. I have a C# application connecting to
System.IO.Directory.GetFiles() returns a string[] . What is the default sort order for the returned
Are System.IO.Compression.GZipStream or System.IO.Compression.Deflate compatible with zlib compression?
I'm using System.IO.Stream.Read(byte[] buffer, int offset, int count) . Is there an alternative to
For Each line As String In System.IO.File.ReadAllLines(file.txt) 'Do Something' Next and Using f As
I'm trying to use System.IO.File.Replace to update a file, and it's throwing System.IOException if
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have the following code: if (System.IO.File.Exists(htmlLocation)) { vEarthBrowser.ObjectForScripting = this; vEarthBrowser.Url = new
Why can't I create a class in VB.NET that inherits System.IO.Directory ? According to
I'm trying to open and read from a serial port using the System.IO.Ports.SerialPort class.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.