CreateMask() приватный Метод

private CreateMask ( int Size ) : uint
Size int
Результат uint
Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="count"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException"></exception>
        public BitWriter2 WriteBits(int count, uint value)
        {
            if (count > _leftBits)
            {
                var bits1 = _leftBits;
                var bits2 = count - _leftBits;
                WriteBits(bits1, value >> (count - bits1));
                WriteBits(bits2, value);
                return(this);
            }

            if (LSB)
            {
                _currentValue |= (value & BitUtils.CreateMask(count)) << (CurrentBits);
            }
            else
            {
                _currentValue |= (value & BitUtils.CreateMask(count)) << (_leftBits - count);
            }
            _leftBits -= count;

            if (_leftBits != 0)
            {
                return(this);
            }

            //Console.WriteLine("Writting: {0:X" + (ByteCapacity * 2) + "}", CurrentValue);
            switch (_byteCapacity)
            {
            case 1:
                Stream.WriteByte((byte)_currentValue);
                break;

            case 2:
                Stream.WriteStruct((ushort)_currentValue);
                break;

            case 4:
                // ReSharper disable once RedundantCast
                Stream.WriteStruct((uint)_currentValue);
                break;

            default:
                throw(new InvalidOperationException());
            }
            ResetValue();

            return(this);
        }
Пример #2
0
        public BitWriter2 WriteBits(int Count, uint Value)
        {
            if (Count > LeftBits)
            {
                int Bits1 = LeftBits;
                int Bits2 = Count - LeftBits;
                WriteBits(Bits1, Value >> (Count - Bits1));
                WriteBits(Bits2, Value);
                return(this);
            }

            if (LSB)
            {
                CurrentValue |= (uint)((Value & BitUtils.CreateMask(Count)) << (CurrentBits));
            }
            else
            {
                CurrentValue |= (uint)((Value & BitUtils.CreateMask(Count)) << (LeftBits - Count));
            }
            LeftBits -= Count;

            if (LeftBits == 0)
            {
                //Console.WriteLine("Writting: {0:X" + (ByteCapacity * 2) + "}", CurrentValue);
                switch (ByteCapacity)
                {
                case 1: Stream.WriteByte((byte)CurrentValue); break;

                case 2: Stream.WriteStruct((ushort)CurrentValue); break;

                case 4: Stream.WriteStruct((uint)CurrentValue); break;
                    throw(new InvalidOperationException());
                }
                ResetValue();
            }

            return(this);
        }