public void GetBytesFromBooleanTest()
        {
            var bc = new SwapBitConverter();
            var bytes = new byte[1];

            bc.GetBytes(true, bytes, 0);
            Assert.AreEqual("01", ByteArrayToString(bytes));

            bc.GetBytes(false, bytes, 0);
            Assert.AreEqual("00", ByteArrayToString(bytes));
        }
        public void GetBytesFromDoubleTest()
        {
            var bc = new SwapBitConverter();
            var bytes = new byte[8];

            bc.GetBytes(1.0, bytes, 0);
            Assert.AreEqual("3F-F0-00-00-00-00-00-00", ByteArrayToString(bytes));

            bc.GetBytes(-1.0, bytes, 0);
            Assert.AreEqual("BF-F0-00-00-00-00-00-00", ByteArrayToString(bytes));
        }
        public void GetBytesFromInt32Test()
        {
            var bc = new SwapBitConverter();
            var bytes = new byte[4];

            bc.GetBytes((Int32)0, bytes, 0);
            Assert.AreEqual("00-00-00-00", ByteArrayToString(bytes));

            bc.GetBytes((Int32)1, bytes, 0);
            Assert.AreEqual("00-00-00-01", ByteArrayToString(bytes));

            bc.GetBytes((Int32)(-1), bytes, 0);
            Assert.AreEqual("FF-FF-FF-FF", ByteArrayToString(bytes));

            bc.GetBytes(Int32.MinValue, bytes, 0);
            Assert.AreEqual("80-00-00-00", ByteArrayToString(bytes));

            bc.GetBytes(Int32.MaxValue, bytes, 0);
            Assert.AreEqual("7F-FF-FF-FF", ByteArrayToString(bytes));
        }
        public void ToUInt64Test()
        {
            var bc = new SwapBitConverter();

            Assert.AreEqual(1UL, bc.ToUInt64(new byte[] { 0, 0, 0, 0, 0, 0, 0, 1 }, 0));
            Assert.AreEqual(65536UL, bc.ToUInt64(new byte[] { 0, 0, 0, 0, 0, 1, 0, 0 }, 0));
            Assert.AreEqual(4294967296UL, bc.ToUInt64(new byte[] { 0, 0, 0, 1, 0, 0, 0, 0 }, 0));
            Assert.AreEqual(281474976710656UL, bc.ToUInt64(new byte[] { 0, 1, 0, 0, 0, 0, 0, 0 }, 0));
            Assert.AreEqual(18446744073709551615UL, bc.ToUInt64(new byte[] { 255, 255, 255, 255, 255, 255, 255, 255 }, 0));
        }
        public void ToUInt32Test()
        {
            var bc = new SwapBitConverter();

            Assert.AreEqual(1U, bc.ToUInt32(new byte[] { 0, 0, 0, 1 }, 0));
            Assert.AreEqual(65536U, bc.ToUInt32(new byte[] { 0, 1, 0, 0 }, 0));
            Assert.AreEqual(4294967295U, bc.ToUInt32(new byte[] { 255, 255, 255, 255 }, 0));
        }
        public void ToUInt16Test()
        {
            var bc = new SwapBitConverter();

            Assert.AreEqual(1U, bc.ToUInt16(new byte[] { 0, 1 }, 0));
            Assert.AreEqual(256U, bc.ToUInt16(new byte[] { 1, 0 }, 0));
            Assert.AreEqual(257U, bc.ToUInt16(new byte[] { 1, 1 }, 0));
            Assert.AreEqual(65535U, bc.ToUInt16(new byte[] { 255, 255 }, 0));
        }
        public void ToSingleTest()
        {
            var bc = new SwapBitConverter();

            Assert.AreEqual(1.0f, bc.ToSingle(new byte[] { 63, 128, 0, 0 }, 0));
            Assert.AreEqual(-1.0f, bc.ToSingle(new byte[] { 191, 128, 0, 0 }, 0));
        }
        public void ToSByteTest()
        {
            var bc = new SwapBitConverter();

            Assert.AreEqual(0, bc.ToSByte(new byte[] { 0 }, 0));
            Assert.AreEqual(1, bc.ToSByte(new byte[] { 1 }, 0));
            Assert.AreEqual(127, bc.ToSByte(new byte[] { 127 }, 0));
            Assert.AreEqual(-128, bc.ToSByte(new byte[] { 128 }, 0));
            Assert.AreEqual(-1, bc.ToSByte(new byte[] { 255 }, 0));
        }
        public void ToInt64Test()
        {
            var bc = new SwapBitConverter();

            Assert.AreEqual(1L, bc.ToInt64(new byte[] { 0, 0, 0, 0, 0, 0, 0, 1 }, 0));
            Assert.AreEqual(65536L, bc.ToInt64(new byte[] { 0, 0, 0, 0, 0, 1, 0, 0 }, 0));
            Assert.AreEqual(4294967296L, bc.ToInt64(new byte[] { 0, 0, 0, 1, 0, 0, 0, 0 }, 0));
            Assert.AreEqual(281474976710656L, bc.ToInt64(new byte[] { 0, 1, 0, 0, 0, 0, 0, 0 }, 0));
            Assert.AreEqual(-1L, bc.ToInt64(new byte[] { 255, 255, 255, 255, 255, 255, 255, 255 }, 0));
        }
Esempio n. 10
0
        public void ToInt32Test()
        {
            var bc = new SwapBitConverter();

            Assert.AreEqual(1, bc.ToInt32(new byte[] { 0, 0, 0, 1 }, 0));
            Assert.AreEqual(65536, bc.ToInt32(new byte[] { 0, 1, 0, 0 }, 0));
            Assert.AreEqual(-1, bc.ToInt32(new byte[] { 255, 255, 255, 255 }, 0));
        }
Esempio n. 11
0
        public void ToInt16Test()
        {
            var bc = new SwapBitConverter();

            Assert.AreEqual(1, bc.ToInt16(new byte[] { 0, 1 }, 0));
            Assert.AreEqual(256, bc.ToInt16(new byte[] { 1, 0 }, 0));
            Assert.AreEqual(257, bc.ToInt16(new byte[] { 1, 1 }, 0));
            Assert.AreEqual(-1, bc.ToInt16(new byte[] { 255, 255 }, 0));
            Assert.AreEqual(-32768, bc.ToInt16(new byte[] { 128, 0 }, 0));
            Assert.AreEqual(32767, bc.ToInt16(new byte[] { 127, 255 }, 0));
        }
Esempio n. 12
0
        public void ToDoubleTest()
        {
            var bc = new SwapBitConverter();

            Assert.AreEqual(1.0, bc.ToDouble(new byte[] { 63, 240, 0, 0, 0, 0, 0, 0 }, 0));
            Assert.AreEqual(-1.0, bc.ToDouble(new byte[] { 191, 240, 0, 0, 0, 0, 0, 0 }, 0));
        }
Esempio n. 13
0
        public void ToBooleanTest()
        {
            var bc = new SwapBitConverter();

            Assert.IsTrue(bc.ToBoolean(new byte[] { 1 }, 0));
            Assert.IsTrue(bc.ToBoolean(new byte[] { 8 }, 0));
            Assert.IsFalse(bc.ToBoolean(new byte[] { 0 }, 0));
        }
Esempio n. 14
0
        public void GetBytesFromUInt64Test()
        {
            var bc = new SwapBitConverter();
            var bytes = new byte[8];

            bc.GetBytes(0UL, bytes, 0);
            Assert.AreEqual("00-00-00-00-00-00-00-00", ByteArrayToString(bytes));

            bc.GetBytes(1UL, bytes, 0);
            Assert.AreEqual("00-00-00-00-00-00-00-01", ByteArrayToString(bytes));

            bc.GetBytes(UInt64.MinValue, bytes, 0);
            Assert.AreEqual("00-00-00-00-00-00-00-00", ByteArrayToString(bytes));

            bc.GetBytes(UInt64.MaxValue, bytes, 0);
            Assert.AreEqual("FF-FF-FF-FF-FF-FF-FF-FF", ByteArrayToString(bytes));
        }