本文整理汇总了C#中Org.BouncyCastle.Math.BigInteger.And方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.And方法的具体用法?C# BigInteger.And怎么用?C# BigInteger.And使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Org.BouncyCastle.Math.BigInteger
的用法示例。
在下文中一共展示了BigInteger.And方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestMod
public void TestMod()
{
// TODO Basic tests
for (int rep = 0; rep < 100; ++rep)
{
int diff = random.Next(25);
BigInteger a = new BigInteger(100 - diff, 0, random);
BigInteger b = new BigInteger(100 + diff, 0, random);
BigInteger c = new BigInteger(10 + diff, 0, random);
BigInteger d = a.Multiply(b).Add(c);
BigInteger e = d.Mod(a);
Assert.AreEqual(c, e);
BigInteger pow2 = one.ShiftLeft(random.Next(128));
Assert.AreEqual(b.And(pow2.Subtract(one)), b.Mod(pow2));
}
}
示例2: TestDivideAndRemainder
public void TestDivideAndRemainder()
{
// TODO More basic tests
BigInteger n = new BigInteger(48, random);
BigInteger[] qr = n.DivideAndRemainder(one);
Assert.AreEqual(n, qr[0]);
Assert.AreEqual(zero, qr[1]);
for (int rep = 0; rep < 10; ++rep)
{
BigInteger a = new BigInteger(100 - rep, 0, random);
BigInteger b = new BigInteger(100 + rep, 0, random);
BigInteger c = new BigInteger(10 + rep, 0, random);
BigInteger d = a.Multiply(b).Add(c);
BigInteger[] es = d.DivideAndRemainder(a);
Assert.AreEqual(b, es[0]);
Assert.AreEqual(c, es[1]);
}
// Special tests for power of two since uses different code path internally
for (int i = 0; i < 100; ++i)
{
int shift = random.Next(64);
BigInteger a = one.ShiftLeft(shift);
BigInteger b = new BigInteger(64 + random.Next(64), random);
BigInteger bShift = b.ShiftRight(shift);
BigInteger bMod = b.And(a.Subtract(one));
string data = "shift=" + shift +", b=" + b.ToString(16);
qr = b.DivideAndRemainder(a);
Assert.AreEqual(bShift, qr[0], data);
Assert.AreEqual(bMod, qr[1], data);
qr = b.DivideAndRemainder(a.Negate());
Assert.AreEqual(bShift.Negate(), qr[0], data);
Assert.AreEqual(bMod, qr[1], data);
qr = b.Negate().DivideAndRemainder(a);
Assert.AreEqual(bShift.Negate(), qr[0], data);
Assert.AreEqual(bMod.Negate(), qr[1], data);
qr = b.Negate().DivideAndRemainder(a.Negate());
Assert.AreEqual(bShift, qr[0], data);
Assert.AreEqual(bMod.Negate(), qr[1], data);
}
}