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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:54:42+00:00 2026-05-14T01:54:42+00:00

I have a stream of bytes which contains a flag which identifies the endianness

  • 0

I have a stream of bytes which contains a flag which identifies the endianness of the data in the header. I want to read the doubles from the stream, which will presumably need to be different if the endianness of the data in the header is different?

I am currently using a BinaryReader and calling ReadDouble to read the data from the stream, but if the endianness flag indicates that the data stream has a different endianness than the machine architecture then presumably this will not work?

How should this be handled? Should I check the endianness of my data against that of the current machine then when I want to read a double instead read the bytes raw into a byte array and do array.Reverse to reverse the data before using BitConverter.ToDouble () with the reversed data and a zero offset?

I could just test this but I do not have a source of data for both endianness so am a bit concerned about creating test data to test the parsing and this being different from what ‘real’ data might look like.

  • 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-14T01:54:42+00:00Added an answer on May 14, 2026 at 1:54 am

    if the endianness flag indicates that the data stream has a different endianness than the machine architecture then presumably this will not work?

    First – the bit order is abstracted from you. Unless you are twiddling bits, you don’t care.

    The byte order is a different thing. For a 4-byte quantity, it can be least-significant-byte first or most-significant-byte first. I don’t know what the ReadDouble() uses, but if you are using a BinaryReader on one end of the wire and a BinaryWriter on the other, then once again, you don’t care. It should be written in the same order as it is read, without regard for endianness.

    The only case where you care, it seems to me, is if you don’t use .NET on the other end of the wire. In that case you must make sure that the bytes are in the proper order, using a scheme similar to what you described. (Array.Reverse, etc).

    Normally applications that face this problem use a multi-byte signature to indicate clearly the order. In other words, write 0x01020304 to the stream, and on the reader side, if you get 0x04030201, you know you’ve got a difference in endianness.

    I could just test this but I do not have a source of data for both endianness …

    Well you have to fix that. You can’t develop without a capability to test what you’re developing. It also begs the question: if you don’t have a source that would use different endianness, then why are you worried about the issue at all?

    See also:
    – Reversing byte order in .NET
    – A class for choosing the endianness of BitConverter

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

Sidebar

Related Questions

I have a stream of bytes which actually (if put right) will form a
I have a Stream of audio data coming from my mic for which I
I have a stream of data that I want to place into a container.
I have a stream of data coming in over the serial line from an
I have a stream of bytes (given by a BufferedInputStream) which represents a sequence
I want to create a memory stream which contains int32, int16, single values. Using
I have a little web server application which reads X bytes from a file
i'd like to read binary data from a blob, using the Stream interface around
I have written a code which streams bytes from another server to my server
I have a byte stream that may be UTF-8 data or it may be

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.