本文整理匯總了C#中BigInteger.SetBit方法的典型用法代碼示例。如果您正苦於以下問題:C# BigInteger.SetBit方法的具體用法?C# BigInteger.SetBit怎麽用?C# BigInteger.SetBit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類BigInteger
的用法示例。
在下文中一共展示了BigInteger.SetBit方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GenerateSearchBase
protected override BigInteger GenerateSearchBase(int bits, object Context)
{
if (Context == null) throw new ArgumentNullException ("Context");
BigInteger ret = new BigInteger ((BigInteger)Context);
ret.SetBit (0);
return ret;
}
示例2: TestSetBit
public void TestSetBit()
{
Assert.AreEqual(One, Zero.SetBit(0));
Assert.AreEqual(One, One.SetBit(0));
Assert.AreEqual(Three, Two.SetBit(0));
Assert.AreEqual(Two, Zero.SetBit(1));
Assert.AreEqual(Three, One.SetBit(1));
Assert.AreEqual(Two, Two.SetBit(1));
// TODO Tests for setting bits in negative numbers
// TODO Tests for setting extended bits
for (int i = 0; i < 10; ++i)
{
var n = new BigInteger(128, Rnd);
for (int j = 0; j < 10; ++j)
{
int pos = Rnd.Next(128);
BigInteger m = n.SetBit(pos);
bool test = m.ShiftRight(pos).Remainder(Two).Equals(One);
Assert.IsTrue(test);
}
}
for (int i = 0; i < 100; ++i)
{
BigInteger pow2 = One.ShiftLeft(i);
BigInteger minusPow2 = pow2.Negate();
Assert.AreEqual(pow2, pow2.SetBit(i));
Assert.AreEqual(minusPow2, minusPow2.SetBit(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.Or(One.ShiftLeft(j)), bigI.SetBit(j), data);
Assert.AreEqual(negI.Or(One.ShiftLeft(j)), negI.SetBit(j), data);
}
}
}
示例3: SetBit_pos_outside
public void SetBit_pos_outside()
{
BigInteger x = new BigInteger(1, 0xFFFF0000, 0xFFFF0000);
BigInteger y = x.SetBit(99);
Expect(SameValue(y,1,new uint[] { 8, 0, 0xFFFF0000, 0xFFFF0000}));
}
示例4: SetBit_pos_inside_initial_set
public void SetBit_pos_inside_initial_set()
{
BigInteger x = new BigInteger(1, 0xFFFF0000, 0xFFFF0000);
BigInteger y = x.SetBit(56);
Expect(y, SameAs(x));
}
示例5: SetBit_pos_inside_initial_clear
public void SetBit_pos_inside_initial_clear()
{
BigInteger x = new BigInteger(1, 0xFFFF0000, 0xFFFF0000);
BigInteger w = new BigInteger(1, 0xFFFF0080, 0xFFFF0000);
BigInteger y = x.SetBit(39);
Expect(y == w);
}
示例6: SetBit_neg_inside_initial_clear
public void SetBit_neg_inside_initial_clear()
{
BigInteger x = new BigInteger(-1, 0xFFFF0000, 0xFFFF0000);
BigInteger w = new BigInteger(-1, 0xFEFF0000, 0xFFFF0000);
BigInteger y = x.SetBit(56);
Expect(y == w);
}