Little endian and big-endian

So I have started developing using Unity. This mean that I am now programming in c# as opposed to Java. There is not that many differences String is string (small s) and the collection classes are called something else.

Today I had to reimplement our protocol parser in C# and it was mostely copy/paste and looking up the appropiate functions. The protocol is rather advanced and has a magic keyword in the beginning for a simple security check. So I hooked the Unity (C#) up with our Java backend and immidiatly got an server error “magic key missing”. Ok my first thought was that i messed up my byte order and sent the bytestream into the local C# protocol parse in order to debug.

I got no errors….

I wrote out the key on the server side and got some apparently random number, but if I changed what the client wrote the new “random” key. Lucky a co-worked came by and suggested Endian…

And yes C# order is in small endian and the java side expects the bytes in big endian order (network order). This is why i’ll never be out of the job…


Good discussion about the topic


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s