Lidgren.Network.NetBigInteger.ShiftLeft C# (CSharp) Method

ShiftLeft() public method

public ShiftLeft ( int n ) : NetBigInteger
n int
return NetBigInteger
        public NetBigInteger ShiftLeft(
			int n)
        {
            if (m_sign == 0 || m_magnitude.Length == 0)
                return Zero;

            if (n == 0)
                return this;

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

            NetBigInteger result = new NetBigInteger(m_sign, ShiftLeft(m_magnitude, n), true);

            if (m_numBits != -1)
            {
                result.m_numBits = m_sign > 0
                    ? m_numBits
                    : m_numBits + n;
            }

            if (m_numBitLength != -1)
            {
                result.m_numBitLength = m_numBitLength + n;
            }

            return result;
        }

Same methods

NetBigInteger::ShiftLeft ( int mag, int n ) : int[]

Usage Example

Example #1
0
		public NetBigInteger Multiply(
			NetBigInteger val)
		{
			if (m_sign == 0 || val.m_sign == 0)
				return Zero;

			if (val.QuickPow2Check()) // val is power of two
			{
				NetBigInteger result = ShiftLeft(val.Abs().BitLength - 1);
				return val.m_sign > 0 ? result : result.Negate();
			}

			if (QuickPow2Check()) // this is power of two
			{
				NetBigInteger result = val.ShiftLeft(Abs().BitLength - 1);
				return m_sign > 0 ? result : result.Negate();
			}

			int maxBitLength = BitLength + val.BitLength;
			int resLength = (maxBitLength + BitsPerInt - 1) / BitsPerInt;

			int[] res = new int[resLength];

			if (val == this)
			{
				Square(res, m_magnitude);
			}
			else
			{
				Multiply(res, m_magnitude, val.m_magnitude);
			}

			return new NetBigInteger(m_sign * val.m_sign, res, true);
		}