Org.BouncyCastle.Math.BigInteger.TestBit C# (CSharp) Method

TestBit() public method

public TestBit ( int n ) : bool
n int
return bool
		public bool TestBit(
			int n)
		{
			if (n < 0)
				throw new ArithmeticException("Bit position must not be negative");

			if (sign < 0)
				return !Not().TestBit(n);

			int wordNum = n / 32;
			if (wordNum >= magnitude.Length)
				return false;

			int word = magnitude[magnitude.Length - 1 - wordNum];
			return ((word >> (n % 32)) & 1) > 0;
		}

Usage Example

Exemplo n.º 1
0
		private static ECPoint ImplShamirsTrick(ECPoint P, BigInteger k,
			ECPoint Q, BigInteger l)
		{
			int m = System.Math.Max(k.BitLength, l.BitLength);
			ECPoint Z = P.Add(Q);
			ECPoint R = P.Curve.Infinity;

			for (int i = m - 1; i >= 0; --i)
			{
				R = R.Twice();

				if (k.TestBit(i))
				{
					if (l.TestBit(i))
					{
						R = R.Add(Z);
					}
					else
					{
						R = R.Add(P);
					}
				}
				else
				{
					if (l.TestBit(i))
					{
						R = R.Add(Q);
					}
				}
			}

			return R;
		}
All Usage Examples Of Org.BouncyCastle.Math.BigInteger::TestBit