当前位置: 首页>>代码示例>>C#>>正文


C# BigInteger.And方法代码示例

本文整理汇总了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));
			}
		}
开发者ID:randombit,项目名称:hacrypto,代码行数:19,代码来源:BigIntegerTest.cs

示例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);
			}
		}
开发者ID:randombit,项目名称:hacrypto,代码行数:49,代码来源:BigIntegerTest.cs


注:本文中的Org.BouncyCastle.Math.BigInteger.And方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。