Recurity.Swf.BitStream.WriteBits C# (CSharp) Method

WriteBits() public method

Fails for the following szenario : bits.WriteBits( 3 , 1 ), RGB.Write() RGB is #ff bits would look like following : 00000000 11111111 11111111 11111111
public WriteBits ( int numberOfBits, ulong data ) : void
numberOfBits int
data ulong
return void
        public void WriteBits(int numberOfBits, ulong data)
        {
            if (numberOfBits < 0)
                throw new ArgumentOutOfRangeException("numberOfBits < 1");

            if (0 == numberOfBits)
                return;

            for (int i = (numberOfBits - 1); i >= 0; i--)
            {
                byte bit = (byte)((data >> i) & 0x01);
                _currentByte = (byte)((_currentByte << 1) | bit);

                if (7 == _bitPos)
                {
                    _backend.WriteByte(_currentByte);
                    _currentByte = 0;
                }

                _bitPos = ((_bitPos + 1) % 8);
            }
        }

Same methods

BitStream::WriteBits ( int numberOfBits, int data ) : void

Usage Example

Exemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="output"></param>
        public override void Write(Stream output)
        {
            BinaryWriter bw = new BinaryWriter(output);
            BitStream bits = new BitStream(output);

            bw.Write(this._initialSampleLeft);
            bits.WriteBits(6, (Int32)this._initialIndexLeft);
            bits.WriteFlush();

            bw.Write(this._initialSampleRight);
            bits.WriteBits(6, (Int32)this._initialIndexRight);
            bits.WriteFlush();

            output.Write(this._adpcmCodeData, 0, this._adpcmCodeData.Length);
        }
All Usage Examples Of Recurity.Swf.BitStream::WriteBits