本文整理汇总了C#中Org.BouncyCastle.Math.BigInteger.ClearBit方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.ClearBit方法的具体用法?C# BigInteger.ClearBit怎么用?C# BigInteger.ClearBit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Org.BouncyCastle.Math.BigInteger
的用法示例。
在下文中一共展示了BigInteger.ClearBit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestClearBit
public void TestClearBit()
{
Assert.AreEqual(zero, zero.ClearBit(0));
Assert.AreEqual(zero, one.ClearBit(0));
Assert.AreEqual(two, two.ClearBit(0));
Assert.AreEqual(zero, zero.ClearBit(1));
Assert.AreEqual(one, one.ClearBit(1));
Assert.AreEqual(zero, two.ClearBit(1));
// TODO Tests for clearing bits in negative numbers
// TODO Tests for clearing extended bits
for (int i = 0; i < 10; ++i)
{
BigInteger n = new BigInteger(128, random);
for (int j = 0; j < 10; ++j)
{
int pos = random.Next(128);
BigInteger m = n.ClearBit(pos);
bool test = m.ShiftRight(pos).Remainder(two).Equals(one);
Assert.IsFalse(test);
}
}
for (int i = 0; i < 100; ++i)
{
BigInteger pow2 = one.ShiftLeft(i);
BigInteger minusPow2 = pow2.Negate();
Assert.AreEqual(zero, pow2.ClearBit(i));
Assert.AreEqual(minusPow2.ShiftLeft(1), minusPow2.ClearBit(i));
BigInteger bigI = BigInteger.ValueOf(i);
BigInteger negI = bigI.Negate();
for (int j = 0; j < 10; ++j)
{
string data = "i=" + i + ", j=" + j;
Assert.AreEqual(bigI.AndNot(one.ShiftLeft(j)), bigI.ClearBit(j), data);
Assert.AreEqual(negI.AndNot(one.ShiftLeft(j)), negI.ClearBit(j), data);
}
}
}