CSharpUtils.BitUtils.CreateMask C# (CSharp) Метод

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

private CreateMask ( int Size ) : uint
Size int
Результат uint
		public static uint CreateMask(int Size)
		{
			return (Size == 0) ? 0 : (uint)((1 << Size) - 1);
		}

Usage Example

Пример #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);
        }
All Usage Examples Of CSharpUtils.BitUtils::CreateMask