本文整理匯總了C#中BigInteger.GetLowestSetBit方法的典型用法代碼示例。如果您正苦於以下問題:C# BigInteger.GetLowestSetBit方法的具體用法?C# BigInteger.GetLowestSetBit怎麽用?C# BigInteger.GetLowestSetBit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類BigInteger
的用法示例。
在下文中一共展示了BigInteger.GetLowestSetBit方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: MultiplyPositive
/**
* 'Zeroless' Signed Digit Left-to-Right.
*/
protected override ECPoint MultiplyPositive(ECPoint p, BigInteger k)
{
ECPoint addP = p.Normalize(), subP = addP.Negate();
ECPoint R0 = addP;
int n = k.BitLength;
int s = k.GetLowestSetBit();
int i = n;
while (--i > s)
{
R0 = R0.TwicePlus(k.TestBit(i) ? addP : subP);
}
R0 = R0.TimesPow2(s);
return R0;
}
示例2: MultiplyPositive
/**
* 'Zeroless' Signed Digit Right-to-Left.
*/
protected override ECPoint MultiplyPositive(ECPoint p, BigInteger k)
{
ECPoint R0 = p.Curve.Infinity, R1 = p;
int n = k.BitLength;
int s = k.GetLowestSetBit();
R1 = R1.TimesPow2(s);
int i = s;
while (++i < n)
{
R0 = R0.Add(k.TestBit(i) ? R1 : R1.Negate());
R1 = R1.Twice();
}
R0 = R0.Add(R1);
return R0;
}
示例3: TestGetLowestSetBit
public void TestGetLowestSetBit()
{
for (int i = 0; i < 10; ++i)
{
BigInteger test = new BigInteger(128, 0, Rnd).Add(One);
int bit1 = test.GetLowestSetBit();
Assert.AreEqual(test, test.ShiftRight(bit1).ShiftLeft(bit1));
int bit2 = test.ShiftLeft(i + 1).GetLowestSetBit();
Assert.AreEqual(i + 1, bit2 - bit1);
int bit3 = test.ShiftLeft(13*i + 1).GetLowestSetBit();
Assert.AreEqual(13*i + 1, bit3 - bit1);
}
}
示例4: LucasSequence
private BigInteger[] LucasSequence(
BigInteger P,
BigInteger Q,
BigInteger k)
{
// TODO Research and apply "common-multiplicand multiplication here"
int n = k.BitLength;
int s = k.GetLowestSetBit();
Debug.Assert(k.TestBit(s));
BigInteger Uh = BigInteger.One;
BigInteger Vl = BigInteger.Two;
BigInteger Vh = P;
BigInteger Ql = BigInteger.One;
BigInteger Qh = BigInteger.One;
for (int j = n - 1; j >= s + 1; --j)
{
Ql = ModMult(Ql, Qh);
if (k.TestBit(j))
{
Qh = ModMult(Ql, Q);
Uh = ModMult(Uh, Vh);
Vl = ModReduce(Vh.Multiply(Vl).Subtract(P.Multiply(Ql)));
Vh = ModReduce(Vh.Multiply(Vh).Subtract(Qh.ShiftLeft(1)));
}
else
{
Qh = Ql;
Uh = ModReduce(Uh.Multiply(Vl).Subtract(Ql));
Vh = ModReduce(Vh.Multiply(Vl).Subtract(P.Multiply(Ql)));
Vl = ModReduce(Vl.Multiply(Vl).Subtract(Ql.ShiftLeft(1)));
}
}
Ql = ModMult(Ql, Qh);
Qh = ModMult(Ql, Q);
Uh = ModReduce(Uh.Multiply(Vl).Subtract(Ql));
Vl = ModReduce(Vh.Multiply(Vl).Subtract(P.Multiply(Ql)));
Ql = ModMult(Ql, Qh);
for (int j = 1; j <= s; ++j)
{
Uh = ModMult(Uh, Vl);
Vl = ModReduce(Vl.Multiply(Vl).Subtract(Ql.ShiftLeft(1)));
Ql = ModMult(Ql, Ql);
}
return new BigInteger[] { Uh, Vl };
}