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

GetBits() public method

public GetBits ( UInt32 numerOfBits ) : UInt32
numerOfBits System.UInt32
return System.UInt32
        public UInt32 GetBits(UInt32 numerOfBits)
        {
            UInt32 ret = 0;

            for (uint i = 0; i < numerOfBits; i++)
            {
                if (0 == _bitPos)
                {
                    int backendInput = _backend.ReadByte();
                    if (-1 == backendInput)
                        throw new EndOfStreamException();
                    _currentByte = (byte)backendInput;
                }

                byte mask = (byte)(0x80 >> (int)_bitPos);
                int shift = (7 - (int)_bitPos);
                byte bit = (byte)((_currentByte & mask) >> shift);
                ret = (ret << 1) | bit;

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

            return ret;
        }

Usage Example

Exemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inout"></param>
        /// <param name="bits"></param>
        public override void Parse(Stream inout, BitStream bits)
        {
            this._numbits = (UInt32)bits.GetBits(4);

            this._generalLineFlag = (0 != bits.GetBits(1)) ? true : false;

            if (this._generalLineFlag)
            {
                this._deltaX = (Int32)bits.GetBitsSigned((UInt32)this._numbits + 2);
                this._deltaY = (Int32)bits.GetBitsSigned((UInt32)this._numbits + 2);
            }
            else
            {
                this._vertLineFlag = (0 != bits.GetBits(1)) ? true : false;

                if (this._vertLineFlag)
                {
                    this._deltaY = (Int32)bits.GetBitsSigned((UInt32)this._numbits + 2);
                }
                else
                {
                    this._deltaX = (Int32)bits.GetBitsSigned((UInt32)this._numbits + 2);
                }
            }
        }
All Usage Examples Of Recurity.Swf.BitStream::GetBits