示例#1
0
        public void ConvertInt16ToBytesTestEndianness()
        {
            Int16 testVal = 0x6985;

            byte[] bigEndian =
                SerializeUtilities.ConvertInt16ToByteArray(testVal, Endianness.big_endian);
            byte[] littleEndian =
                SerializeUtilities.ConvertInt16ToByteArray(testVal, Endianness.little_endian);
            Assert.AreEqual((byte)((testVal >> 8) & 0xFF), bigEndian[0]);
            Assert.AreEqual((byte)(testVal & 0xFF), bigEndian[1]);
            Assert.AreEqual((byte)(testVal & 0xFF), littleEndian[0]);
            Assert.AreEqual((byte)((testVal >> 8) & 0xFF), littleEndian[1]);
        }
示例#2
0
        public void ConvertByteArrayToInt16()
        {
            Int16 knownVal = 0x1234;

            byte[] littleEndian =
                SerializeUtilities.ConvertInt16ToByteArray(knownVal, Endianness.little_endian);
            byte[] bigEndian =
                SerializeUtilities.ConvertInt16ToByteArray(knownVal, Endianness.big_endian);
            Int16 littleTest =
                SerializeUtilities.ConvertByteArrayToInt16(littleEndian, Endianness.little_endian);
            Int16 bigTest =
                SerializeUtilities.ConvertByteArrayToInt16(bigEndian, Endianness.big_endian);

            Assert.AreEqual((byte)((knownVal >> 8) & 0xFF), bigEndian[0]);
            Assert.AreEqual((byte)(knownVal & 0xFF), bigEndian[1]);

            Assert.AreEqual((byte)((knownVal >> 8) & 0xFF), littleEndian[1]);
            Assert.AreEqual((byte)(knownVal & 0xFF), littleEndian[0]);
        }