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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:52:52+00:00 2026-05-16T22:52:52+00:00

Let’s say we have a binary file that contains 2 bytes that form an

  • 0

Let’s say we have a binary file that contains 2 bytes that form an integer, in reverse.

So for example, the bytes show like this: (hexadecimal)

EB 03 00 00

Which should be interpreted as this:

00 00 03 EB

Which C# should be able to input as decimal 1003. Is this possible if you have the EB and 03 bytes already in memory in 2 different variables? Is there some math I can apply here to form decimal 1003 from the numbers 235 and 3? Or should I do it completely different?

Thanks in advance!

  • 1 1 Answer
  • 1 View
  • 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-16T22:52:52+00:00Added an answer on May 16, 2026 at 10:52 pm

    What you talk about is called Endianness, in particular Little Endian format.

    In C#, it’s probably easiest to use a BinaryReader or BinaryWriter to read from binary files which wrap the correct conversion of the byte order.

    The following sample shows how to use a BinaryReader to get the correct integer interpretation of a number in Little Endian format:

    using System.IO;
    
    class EndiannessSample
    {
        static void Main(string[] args)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                // write bytes in little-endian format
                ms.WriteByte(0xEB);
                ms.WriteByte(0x03);
                ms.WriteByte(0x00);
                ms.WriteByte(0x00);
                ms.Position = 0;
    
                using (BinaryReader reader = new BinaryReader(ms))
                {
                    int i = reader.ReadInt32(); // decimal value of i is 1003
                }
            }
        }
    }
    

    Little endian is the standard on Intel (and Windows) platforms. In case you have to deal with data in Big Endian format (e.g. when importing files created on an old Macintosh) there is no direct support within .NET. You can write a simple utility function for converting endianness using the BitConverter class. In the sample above you could do the following to cope with Big Endian (on a Little Endian platform):

    using (MemoryStream ms = new MemoryStream())
    {
        // write bytes in big-endian format
        ms.WriteByte(0x00);
        ms.WriteByte(0x00);
        ms.WriteByte(0x03);
        ms.WriteByte(0xEB);
            
        ms.Position = 0;
        using (BinaryReader reader = new BinaryReader(ms))
        {
            byte[] temp = reader.ReadBytes(4);
            if (BitConverter.IsLittleEndian)
            {
                // reverse the byte order only if we are on a little-endian system,
                // because the BitConverter is aware of the endianness of the system
                //
                Array.Reverse(temp);
            }
            int i = BitConverter.ToInt32(temp, 0);
        }
    }
    

    LukeH provided a link that further discusses problems related to Endianness, e.g. when targeting Xbox 360 (which happens to be a Big Endian platform):

    One Little, Two Little, Three Little Endian… 0x0A Big Endian Bugs

    Update

    The MiscUtil library provides a binary reader/writer class that can be configured for a specific Endianness:

    MiscUtil.IO.EndianBinary{Writer/Reader}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me explain best with an example. Say you have node class that can
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say that I have a set of relations that looks like this: relations
Let's have an example like below: package xliiv.sandbox; import android.app.Activity; import android.os.Bundle; import android.util.Log;
Let's say that I have a SQLite database that I create in a separate
Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say I have multiple requirements for a password. The first is that the
Let's say that I have a date in R and it's formatted as follows.

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.