Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Endianness in programming languages

Well, the "Endianness" theme was always a little bit confusing to me, but i have never faced any problems which required me to even think about the default behaviour of binary writers/readers that i used. I am writing a PNG decoder in c# right now. PNG file format specification states that all numbers are stored in a big endian notation (which i find very natural). However, i was very surprised when i noticed, that .NET's BinaryReader/Writer works with a little endian notation. What confused me even more, was the fact, that java's binary IO works with a big endian notation (a am not a java programmer, so maybe i am wrong). So i started to think about the following questions:

1 - Why are things as they are? I mean a Base Class Library default behaviour. 2 - Why there is no way to choose a preferred notation when using .NET's System.IO ?

I am currently using Jon Skeet's MiscUtil and it works like a charm (thanks, man =) ). But it would be cool to see this functionality in a Base Class Library.

like image 705
n535 Avatar asked Feb 28 '10 20:02

n535


1 Answers

This is because the code is meant to run as well as possible on the most important platform. C#/.NET is from Microsoft and runs mostly on x86 platforms. x86 is little-endian, so it makes sense to make the library little-endian. Java is made by Sun, and the Sun SPARC was big-endian, thus the Java standard was big-endian instead.

like image 196
Johan Kotlinski Avatar answered Oct 21 '22 02:10

Johan Kotlinski