Ejemplo n.º 1
0
 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));
 }
Ejemplo n.º 2
0
 public static int ReadBE4(byte *buf)
 {
     if (BitConverter.IsLittleEndian)
     {
         return((int)BinaryUtility.ByteSwap(*(uint *)buf));
     }
     else
     {
         return(*(int *)buf);
     }
 }
Ejemplo n.º 3
0
 public unsafe static void WriteBESingle(byte *buf, float val)
 {
     if (BitConverter.IsLittleEndian)
     {
         *(uint *)buf = BinaryUtility.ByteSwap(*(uint *)&val);
     }
     else
     {
         *(float *)buf = val;
     }
 }
Ejemplo n.º 4
0
 public static void WriteBE4U(byte *buf, uint val)
 {
     if (BitConverter.IsLittleEndian)
     {
         *(uint *)buf = BinaryUtility.ByteSwap(val);
     }
     else
     {
         *(uint *)buf = val;
     }
 }
Ejemplo n.º 5
0
 public static void WriteBE2(byte *buf, short val)
 {
     if (BitConverter.IsLittleEndian)
     {
         *(ushort *)buf = BinaryUtility.ByteSwap((ushort)val);
     }
     else
     {
         *(short *)buf = val;
     }
 }
Ejemplo n.º 6
0
 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);
     }
 }
Ejemplo n.º 7
0
 public static ushort ReadBE2U(byte *buf)
 {
     if (BitConverter.IsLittleEndian)
     {
         return(BinaryUtility.ByteSwap(*(ushort *)buf));
     }
     else
     {
         return(*(ushort *)buf);
     }
 }
Ejemplo n.º 8
0
 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;
     }
 }
Ejemplo n.º 9
0
 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;
     }
 }
Ejemplo n.º 10
0
 public unsafe static float ReadBESingle(byte *buf)
 {
     if (BitConverter.IsLittleEndian)
     {
         uint v = BinaryUtility.ByteSwap(*(uint *)buf);
         return(*(float *)&v);
     }
     else
     {
         return(*(float *)buf);
     }
 }