Ejemplo n.º 1
0
        public void CanConvertBitArrayToStruct()
        {
            var endianness = Endianness.LittleEndian;
            var bits       = new []
            {
                true, true, true,
                false, false, false,
                true, false, true, false, true, false, true, false, true, false, true, false, true, false, true,
                false, true, false, true, false,
                true, true, true, false, false, false,
            };
            var values = new List <uint>();

            using (var ms = new MemoryStream(new byte[] { 0xE2, 0xAA, 0xAA, 0xB8 }))
            {
                using (var br = new BitsReader(ms))
                {
                    foreach (var size in new ulong[] { 3, 3, 15, 5, 6 })
                    {
                        values.Add(br.ReadStruct <uint>(size, endianness));
                    }
                }
            }
            Assert.AreEqual(0x7, values[0]);
            Assert.AreEqual(0x0, values[1]);
            if (endianness == Endianness.BigEndian)
            {
                Assert.AreEqual(0x5555, values[2]);
            }
            else
            {
                Assert.AreEqual(0x55AA, values[2]);
            }
            Assert.AreEqual(0xA, values[3]);
            Assert.AreEqual(0x38, values[4]);
        }