Michael Davidov <si*****@gmail.com> wrote:
byte []array = {0x00,0x04};
short ashort = BitConverter.ToInt16(array,0);
Console.WriteLine(ashort.ToString());
Why am I wrong to think that this should return a 4 instead of 1024?
Because BitConverter is little-endian in the MS implementation.
Also, is there a way to get a short value of 4 from those 2 bytes
without switching their possition in the byte array?
Yup - use a class which lets you deal with it in a big-endian way.
Fortunately, I have such a class you can use :)
Look at EndianBitConverter in my MiscUtil library
http://www.pobox.com/~skeet/csharp/miscutil
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too