BraintreeEncryption.Library.BouncyCastle.Math.BigInteger.ShiftLeft C# (CSharp) Method

ShiftLeft() public method

public ShiftLeft ( int n ) : BigInteger
n int
return BigInteger
		public BigInteger ShiftLeft(
			int n)
		{
			if (sign == 0 || magnitude.Length == 0)
				return Zero;

			if (n == 0)
				return this;

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

			BigInteger result = new BigInteger(sign, ShiftLeft(magnitude, n), true);

			if (this.nBits != -1)
			{
				result.nBits = sign > 0
					?	this.nBits
					:	this.nBits + n;
			}

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

			return result;
		}

Same methods

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

Usage Example

		public BigInteger Multiply(
			BigInteger val)
		{
			if (sign == 0 || val.sign == 0)
				return Zero;

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

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

			int resLength = (this.BitLength + val.BitLength) / BitsPerInt + 1;
			int[] res = new int[resLength];

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

			return new BigInteger(sign * val.sign, res, true);
		}