コード例 #1
0
        public void ToXXX()
        {
            var sut = new LittleEndianBitConverter();

            var data = new byte[] { 0x03, 0, 0, 0, 0, 0, 0, 0 };

            Check.That(sut.ToBoolean(data, 0)).IsTrue();
            Check.That(sut.ToBoolean(data, 7)).IsFalse();
            Check.That(sut.ToChar(data, 0)).IsEqualTo('\u0003');
            Check.That(sut.ToChar(data, 6)).IsEqualTo('\0');
            Check.That(sut.ToInt16(data, 0)).IsEqualTo(3);
            Check.That(sut.ToInt16(data, 6)).IsEqualTo(0);
            Check.That(sut.ToUInt16(data, 0)).IsEqualTo(3u);
            Check.That(sut.ToUInt16(data, 6)).IsEqualTo(0u);
            Check.That(sut.ToInt32(data, 0)).IsEqualTo(3);
            Check.That(sut.ToInt32(data, 4)).IsEqualTo(0);
            Check.That(sut.ToUInt32(data, 0)).IsEqualTo(3u);
            Check.That(sut.ToUInt32(data, 4)).IsEqualTo(0u);
            Check.That(sut.ToInt64(data, 0)).IsEqualTo(3L);
            Check.That(sut.ToUInt64(data, 0)).IsEqualTo(3UL);

            data = new byte[] { 0, 0, 0, 0, 0, 0, 0x20, 0x41 };
            Check.That(sut.ToSingle(data, 0)).IsEqualTo(0.0f);
            Check.That(sut.ToSingle(data, 4)).IsEqualTo(10.0f);

            data = new byte[] { 0, 0, 0, 0, 0, 0, 0x24, 0x40 };
            Check.That(sut.ToDouble(data, 0)).IsEqualTo(10.0);
        }
コード例 #2
0
        public void LittleEndianBitConverter_Boolean()
        {
            var buffer = new byte[1];

            LittleEndianBitConverter.FillBytes(true, buffer);
            Assert.AreEqual(1, buffer[0]);
            Assert.IsTrue(LittleEndianBitConverter.GetBytes(true).SequenceEqual(buffer));
            Assert.AreEqual(true, LittleEndianBitConverter.ToBoolean(buffer));

            LittleEndianBitConverter.FillBytes(false, buffer);
            Assert.AreEqual(0, buffer[0]);
            Assert.IsTrue(LittleEndianBitConverter.GetBytes(false).SequenceEqual(buffer));
            Assert.AreEqual(false, LittleEndianBitConverter.ToBoolean(buffer));
        }