示例#1
0
        public static void CastBufferToSpan()
        {
            var buffer = new Buffer16();

            Span <ulong> ulongSpan = buffer.AsSpan <ulong>();

            Assert.Equal(2, ulongSpan.Length);
            Assert.True(Unsafe.AreSame(ref Unsafe.As <Buffer16, ulong>(ref buffer), ref ulongSpan[0]));
        }
示例#2
0
        public int ReadBits(int bitCount)
        {
            Debug.Assert(bitCount < 32);

            if (bitCount == 0)
            {
                return(0);
            }

            int mask  = (1 << bitCount) - 1;
            int value = _data.As <int>() & mask;

            Span <ulong> span = _data.AsSpan <ulong>();

            ulong carry = span[1] << (64 - bitCount);

            span[0]   = (span[0] >> bitCount) | carry;
            span[1] >>= bitCount;

            BitsLeft -= bitCount;

            return(value);
        }