Exemplo n.º 1
0
        /// <summary>
        /// Writes a signed integer using 1 to 32 bits
        /// </summary>
        public BitWriter Write(Int32 source, int numberOfBits)
        {
            BitBufferException.Assert((numberOfBits > 0 && numberOfBits <= 32), "Write(int, numberOfBits) can only write between 1 and 32 bits");
            EnsureBufferSize(_lengthBits + numberOfBits);

            if (numberOfBits != 32)
            {
                // make first bit sign
                int signBit = 1 << (numberOfBits - 1);
                if (source < 0)
                {
                    source = (-source - 1) | signBit;
                }
                else
                {
                    source &= (~signBit);
                }
            }

            BitReaderWriter.WriteUInt32((uint)source, numberOfBits, _data, _lengthBits);

            _lengthBits += numberOfBits;

            return(this);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Writes a 32 bit unsigned integer
        /// </summary>
        public BitWriter Write(UInt32 source)
        {
            EnsureBufferSize(_lengthBits + 32);
            BitReaderWriter.WriteUInt32(source, 32, _data, _lengthBits);
            _lengthBits += 32;

            return(this);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Writes a 32 bit signed integer
        /// </summary>
        public BitWriter Write(UInt32 source, int numberOfBits)
        {
            BitBufferException.Assert((numberOfBits > 0 && numberOfBits <= 32), "Write(uint, numberOfBits) can only write between 1 and 32 bits");
            EnsureBufferSize(_lengthBits + numberOfBits);
            BitReaderWriter.WriteUInt32(source, numberOfBits, _data, _lengthBits);
            _lengthBits += numberOfBits;

            return(this);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Writes a 32 bit unsigned integer at a given offset in the buffer
        /// </summary>
        public BitWriter WriteAt(Int32 offset, UInt32 source)
        {
            int newBitLength = Math.Max(_lengthBits, offset + 32);

            EnsureBufferSize(newBitLength);
            BitReaderWriter.WriteUInt32(source, 32, _data, offset);
            _lengthBits = newBitLength;

            return(this);
        }