Вопрос

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