tags:

views:

76

answers:

6

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

Indicates the byte order ("endianness") in which data is stored in this computer architecture.

I notice in Reflector that the field is hard-coded to true in the static constructor of BitConverter.

So my question is, do I need to take account of IsLittleEndian when using the BitConverter - in other words, are there any .Net implementations running on big-endian platforms? And if not, what was the purpose of the field in the first place?

+2  A: 

SOME of the systems that the .NET Micro Framework runs on are (or can be...) big-endian. Version 4.1 introduced support for big-endian architectures.

You'd probably know if you were running on the micro framework, however...

Mark
+1  A: 

If you're MSIL you don't get that guarantee.

Even if it's true for all current architectures, you have no guarantee I don't port .NET to Alpha or PDP11 tomorrow.

Joshua
@Joshua, what guarantee?
Samuel Jack
guarantee of little endian
Joshua
+2  A: 

The .Net Micro Framework 4.1 supports big-endian - Source

Matthieu
+2  A: 
stakx
IP packets are extremely byte-order dependent, so you need to keep that in mind when talking about portability. It's rare to have a project come through that needs low-level network programming, but they're out there.
The Moof
_@The Moof_, good point, thanks for mentioning this!
stakx
+2  A: 

Depends on what you mean by ".Net implementations". I'm not aware of Microsoft .NET Framework version for big-endian platform (but see other answers). But if you mean CLI/CLR implementation, then both Mono and DotGNU have versions for big-endian machines. Mono runs at least on Solaris 10 on Sparc and on Mac OS X on PowerPC. DotGNU has much wider list of available platforms.

Tomek Szpakowicz
A: 

The XBox360 is BigEndian. Robert Unoki from Microsoft has a good blog post about the importance of checking the IsLittleEndian flag - and the bugs that occurred in porting the CLR to XBox360 when the Microsoft developers failed to do so.

Samuel Jack