Endianness is the attribute of a system that indicates whether integers are represented with the most significant byte stored at the lowest address or at the highest address:

"Big-endian" means the most significant byte is on the left end of a word.
"Little-endian" means the most significant byte is on the right end of a word.


Why is endianness important? Suppose you are storing integer values to a file, and you send the file to a machine that uses the opposite endianness as it reads in the value. This causes problems because of endianness; you'll read in reversed values that won't make sense.

Also, endianness might affect your code when you use a type cast that depends on a certain endian being in use.

How do you check for endianness in C#?

The BitConverter class has an IsLittleEndian field to tell you how it will behave, but it doesn't give the choice. The same goes for BinaryReader/BinaryWriter

Example:


class LittleEndDemo
{
public static void Main( )
{
Console.WriteLine("Is Little Endian?");
Console.WriteLine(BitConverter.IsLittleEndian);
Console.ReadKey();
}
}



References:

IBM, Writing endian-independent code in C

BitConverter.IsLittleEndian Field





Answers and Comments


Saved Stories

Sponsored Categories





100 Common Interview Questions, audio book