Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mono Endianness

with .NET things are fairly simple - it is all (including ARM ASFAIK) running little endian .

The question that I have is: what is happing on Mono and (potentially) big endian systems? Do the bits reverse (when compared to x86) in Int32 / Int64 structure or does the framework force little endian rule-set?

Thanks

like image 221
arthur Avatar asked Mar 24 '11 21:03

arthur


People also ask

What is endianness used for?

Endian and endianness (or "byte-order") describe how computers organize the bytes that make up numbers. Each memory storage location has an index or address. Every byte can store an 8-bit number (i.e. between 0x00 and 0xff ), so you must reserve more than one byte to store a larger number.

What is little endian example?

For example, if 4F is stored at storage address 1000, 52 will be at address 1001. In a little-endian system, it would be stored as 524F, with 52 at address 1000 and 4F at 1001.

What is endianness of the CPU?

Endianness is the term used to describe the byte order of data. Big-endian means data is being sent or stored with the Most Significant Byte (MSB) first. Little-endian means data is sent with the Least Significant Byte (LSB) first. A CPU always has an endianness, even for 8 bit CPUs.

What does Little Endian mean?

The little-endian convention is a type of addressing that refers to the order of data stored in memory. In this convention, the least significant bit (or "littlest" end) is first stored at address 0, and subsequent bits are stored incrementally.


1 Answers

Your assertion that all MS .NET are little endian is not correct. It depends on the architecture that you are running on - the CLR spec says so:

From the CLI Annotated Standard (p.161) — Partition I, section 12.6.3: "Byte Ordering":

For data types larger than 1 byte, the byte ordering is dependent on the target CPU. Code that depends on byte ordering may not run on all platforms. [...]

(taken from this SO answer)

See this answer for more information on the internals of BitConverter and how it handles endianness.

like image 130
Oded Avatar answered Oct 16 '22 18:10

Oded