public static void TestBits()
 {
     if (!BitConverter.IsLittleEndian)
     {
         Assert.Fail("BitConverter identifies this system as big endian, which is not currently supported by the engine!");
     }
     else
     {
         byte[] bI = PrimitiveConversionHelper.Int32ToBytes(1 + 512);
         Assert.That(bI.Length == 4, "Bit length (int->bytes)");
         Assert.That(bI[0] == 1, "Bit contents (int->bytes)[0]");
         Assert.That(bI[1] == 2, "Bit contents (int->bytes)[1]");
         Assert.That(bI[2] == 0, "Bit contents (int->bytes)[2]");
         Assert.That(bI[3] == 0, "Bit contents (int->bytes)[3]");
         byte[] bF = PrimitiveConversionHelper.Float32ToBytes(127.125f);
         Assert.That(bF.Length == 4, "Bit length (float->bytes)");
         Assert.That(bF[0] == 0, "Bit contents (float->bytes)[0]");
         Assert.That(bF[1] == 64, "Bit contents (float->bytes)[1]");
         Assert.That(bF[2] == 254, "Bit contents (float->bytes)[2]");
         Assert.That(bF[3] == 66, "Bit contents (float->bytes)[3]");
         Assert.That(PrimitiveConversionHelper.BytesToDouble64(PrimitiveConversionHelper.Double64ToBytes(1.73e5)) == 1.73e5, "Double parseback validity");
     }
 }
예제 #2
0
 /// <summary>
 /// Write an integer (4 bytes).
 /// </summary>
 /// <param name="x">The data.</param>
 public void WriteInt(int x)
 {
     PrimitiveConversionHelper.Int32ToBytes(x, HelperBytes, 0);
     Internal.Write(HelperBytes, 0, 4);
 }