Hello. I have a problem with getting short value from 2 byte array.
I have this code. There are 2 short values in bytes.
byte[] cast = { 18, 152, 00, 80 };
Int32 port = BitConverter.ToInt16(cast, 0); // -26606 - wrong!
Int32 port2 = BitConverter.ToInt16(cast, 2); // 20480 - wrong!
//port and port2 get not correct values
//and I found solution in google
short result1 = (short)(((short)cast[1]) | (short)(cast[0] * 256)); //4760 -
correct!
short result2 = (short)(((short)cast[3]) | (short)(cast[2] * 256)); //80 -
correct!
why it happends? How make BitConverter work correct?