Efficient way to read big endian data in C#
I use the following code to read BigEndian information using BinaryReader but I'm not sure if it is the efficient way of doing it. Is there any better solution? Here is my code: // some code to initialize the stream value // set the length value to the Int32 size BinaryReader reader =new BinaryReader(stream); byte[] bytes = reader.ReadBytes(length); Array.Reverse(bytes); int result = System.BitConverter.ToInt32(temp, 0); CodesInChaos BitConverter.ToInt32 isn't very fast in the first place. I'd simply use public static int ToInt32BigEndian(byte[] buf, int i) { return (buf[i]<<24) | (buf[i+1]<