Which .Net-compatible architectures are not little-endian?

后端 未结 6 1919
醉梦人生
醉梦人生 2021-01-20 11:46

The BitConverter class has a field IsLittleEndian which, according to the documentation:

Indicates the byte order (\"endianness\") in which data is st

6条回答
  •  一个人的身影
    2021-01-20 12:21

    The CLI standard does not proscribe any particular Endianness, so if you want your program to be portable, you should not depend on a particular byte order... unless of course in scenarios where a particular byte ordering is required, such as with some data exchange protocols (thanks to user The Moof for pointing this out).

    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. [...]

    I suspect that you saw a hard-coded value for IsLittleEndian in Reflector because when you downloaded/installed the .NET Framework on your machine, that particular installation package was targeted at a particular platform (e.g. Intel x86, which is Little Endian).

    I could thus imagine that there are other installation packages of the .NET framework that have IsLittleEndian hard-wired to return a different value, depending on the platform that particular installation targets.

提交回复
热议问题