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.

Related Questions

No related questions found

  • 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 58k
  • Answers 58k
  • 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 sed will work in buffered mode when it doesn't print… May 11, 2026 at 8:41 am
  • added an answer There won't be a problem, they are basically independent since… May 11, 2026 at 8:41 am
  • added an answer java.net.URL url = new java.net.URL('http://www.joe90.com/showroom'); String tokens[] = url.getHostname().split('.'); StringBuilder… May 11, 2026 at 8:41 am

Top Members

Trending Tags

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

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.