示例#1
0
        public void LongConversion()
        {
            // TODO: Test more values.
            byte[] max      = new byte[] { 255, 255, 255, 255, 255, 255, 255, 255 };
            long   expected = BitConverter.ToInt64(max);
            long   actual   = ByteArrayConversion.BytesToLong(max);

            Assert.Equal(expected, actual);

            byte[] expectedBytes = BitConverter.GetBytes(long.MaxValue);
            byte[] actualBytes   = ByteArrayConversion.LongToBytes(long.MaxValue);
            Assert.Equal(expectedBytes, actualBytes);
        }
示例#2
0
        public void IntConversion()
        {
            // TODO: Test more values.
            byte[] max      = new byte[] { 255, 255, 255, 255 };
            int    expected = BitConverter.ToInt32(max);
            int    actual   = ByteArrayConversion.BytesToInt(max);

            Assert.Equal(expected, actual);

            byte[] expectedBytes = BitConverter.GetBytes(int.MaxValue);
            byte[] actualBytes   = ByteArrayConversion.IntToBytes(int.MaxValue);
            Assert.Equal(expectedBytes, actualBytes);
        }
示例#3
0
        public void HexConversion()
        {
            string hex = "FC65A311";

            byte[] expected = hex.HexToByteArray();
            byte[] actual   = ByteArrayConversion.HexStringToBytes(hex);
            Assert.Equal(expected, actual);

            byte[] bytes          = new byte[] { 1, 2, 3, 4 };
            string expectedString = BitConverter.ToString(bytes).Replace("-", "");
            string actualString   = ByteArrayConversion.BytesToHexString(bytes);

            Assert.Equal(expectedString, actualString);
        }