Conversion from BigEndian to Little Endia
-
Is there a class available to convert data from Little to BigEndian? Regards Hansjörg
-
Is there a class available to convert data from Little to BigEndian? Regards Hansjörg
-
I need something to convert a byte array (which contains int, int64...) from big to little endian. I don't see any possibitlity to use this class, isn't it? Thanks for your help! Regards Hansjörg
-
Is there a class available to convert data from Little to BigEndian? Regards Hansjörg
Best way is to write some methods yourself, what types do you have to convert?
public static int ReverseEndian(int x) { return ((x<<24) | ((x & 0xff00)<<8) | ((x & 0xff0000)>>8) | (x>>24)); } public static uint ReverseEndian(uint x) { return ((x<<24) | ((x & 0xff00)<<8) | ((x & 0xff0000)>>8) | (x>>24)); } ...
-
Best way is to write some methods yourself, what types do you have to convert?
public static int ReverseEndian(int x) { return ((x<<24) | ((x & 0xff00)<<8) | ((x & 0xff0000)>>8) | (x>>24)); } public static uint ReverseEndian(uint x) { return ((x<<24) | ((x & 0xff00)<<8) | ((x & 0xff0000)>>8) | (x>>24)); } ...
I have to convert all standard types... I hoped that something is available Thanks for your help!
-
I have to convert all standard types... I hoped that something is available Thanks for your help!
I don't know of any implementation that does it, the code I gave was from a program of mine where I also did everything myself. If you have to convert all standard types I would create your own BinaryReader which takes the default BinaryReader as parameter and endian swap each method before passing back.
using System.IO; public class EndianReader : BinaryReader { #region Constructors public EndianReader(Stream stream) : base(stream) { } #endregion #region Methods public override int ReadInt32() { return ReverseEndian(base.ReadInt32()); } #endregion #region Class Methods public static int ReverseEndian(int x) { return ((x << 24) | ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | (x >> 24)); } #endregion }