public void T04_TestByteSwaps() { Assert.AreEqual(unchecked ((short)0x8967), BinaryUtility.ByteSwap((short)0x6789)); Assert.AreEqual((ushort)0x3412, BinaryUtility.ByteSwap((ushort)0x1234)); Assert.AreEqual(unchecked ((int)0x89674523), BinaryUtility.ByteSwap((int)0x23456789)); Assert.AreEqual((uint)0x78563412, BinaryUtility.ByteSwap((uint)0x12345678)); Assert.AreEqual(unchecked ((int)0x89674523), BinaryUtility.ByteSwap((int)0x23456789)); Assert.AreEqual(unchecked ((long)0xEFCDAB9078563412), BinaryUtility.ByteSwap((long)0x1234567890ABCDEF)); Assert.AreEqual((ulong)0xEFCDAB9078563412, BinaryUtility.ByteSwap((ulong)0x1234567890ABCDEF)); }
public static int ReadBE4(byte *buf) { if (BitConverter.IsLittleEndian) { return((int)BinaryUtility.ByteSwap(*(uint *)buf)); } else { return(*(int *)buf); } }
public unsafe static void WriteBESingle(byte *buf, float val) { if (BitConverter.IsLittleEndian) { *(uint *)buf = BinaryUtility.ByteSwap(*(uint *)&val); } else { *(float *)buf = val; } }
public static void WriteBE4U(byte *buf, uint val) { if (BitConverter.IsLittleEndian) { *(uint *)buf = BinaryUtility.ByteSwap(val); } else { *(uint *)buf = val; } }
public static void WriteBE2(byte *buf, short val) { if (BitConverter.IsLittleEndian) { *(ushort *)buf = BinaryUtility.ByteSwap((ushort)val); } else { *(short *)buf = val; } }
public static ulong ReadBE8U(byte *buf) { if (BitConverter.IsLittleEndian) { return(((ulong)BinaryUtility.ByteSwap(*(uint *)buf) << 32) | BinaryUtility.ByteSwap(*(uint *)(buf + 4))); } else { return(*(ulong *)buf); } }
public static ushort ReadBE2U(byte *buf) { if (BitConverter.IsLittleEndian) { return(BinaryUtility.ByteSwap(*(ushort *)buf)); } else { return(*(ushort *)buf); } }
public unsafe static void WriteBEDouble(byte *buf, double val) { if (BitConverter.IsLittleEndian) { *(uint *)buf = BinaryUtility.ByteSwap(*((uint *)&val + 1)); *(uint *)(buf + 4) = BinaryUtility.ByteSwap(*(uint *)&val); } else { *(double *)buf = val; } }
public static void WriteBE8U(byte *buf, ulong val) { if (BitConverter.IsLittleEndian) { *(uint *)buf = BinaryUtility.ByteSwap(*((uint *)&val + 1)); *(uint *)(buf + 4) = BinaryUtility.ByteSwap(*(uint *)&val); } else { *(ulong *)buf = val; } }
public unsafe static float ReadBESingle(byte *buf) { if (BitConverter.IsLittleEndian) { uint v = BinaryUtility.ByteSwap(*(uint *)buf); return(*(float *)&v); } else { return(*(float *)buf); } }