質問

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