Lidgren.Network.NetBigInteger.ShiftRight C# (CSharp) Метод

ShiftRight() публичный Метод

public ShiftRight ( int n ) : NetBigInteger
n int
Результат NetBigInteger
        public NetBigInteger ShiftRight(
			int n)
        {
            if (n == 0)
                return this;

            if (n < 0)
                return ShiftLeft(-n);

            if (n >= BitLength)
                return (m_sign < 0 ? One.Negate() : Zero);

            //			int[] res = (int[]) magnitude.Clone();
            //
            //			res = ShiftRightInPlace(0, res, n);
            //
            //			return new BigInteger(sign, res, true);

            int resultLength = (BitLength - n + 31) >> 5;
            int[] res = new int[resultLength];

            int numInts = n >> 5;
            int numBits = n & 31;

            if (numBits == 0)
            {
                Array.Copy(m_magnitude, 0, res, 0, res.Length);
            }
            else
            {
                int numBits2 = 32 - numBits;

                int magPos = m_magnitude.Length - 1 - numInts;
                for (int i = resultLength - 1; i >= 0; --i)
                {
                    res[i] = (int)((uint)m_magnitude[magPos--] >> numBits);

                    if (magPos >= 0)
                    {
                        res[i] |= m_magnitude[magPos] << numBits2;
                    }
                }
            }

            Debug.Assert(res[0] != 0);

            return new NetBigInteger(m_sign, res, false);
        }