문제

Im using a System.IO.BinaryReader to read a data from a serialized file. The file is big endian. So what I did to read the Int64 (long) from the stream was read 8 bytes from it. What I need to do is convert those 8 bytes of big endian into little endian long representation.

I can't use System.BitConverter as it will be compiled with Mono for use on Linux which could be running on big endian and with Visual Studio for Windows which is little endian.

도움이 되었습니까?

해결책

You can use System.Net.IPAddress.NetworkToHostOrder or System.Net.IPAddress.HostToNetworkOrder

For ex, System.Net.IPAddress.HostToNetworkOrder(0x0123456789abcdefl) would return efcdab8967452301

다른 팁

If you're going to end up using Mono anyway, you can use DataConvert.

Works fine on Windows too. I'm using it in one of my projects.

John Skeet's miscutil library implements a BigEndianBitConverter.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top