當前位置: 首頁>>代碼示例>>C#>>正文


C# BigInteger.FlipBit方法代碼示例

本文整理匯總了C#中BigInteger.FlipBit方法的典型用法代碼示例。如果您正苦於以下問題:C# BigInteger.FlipBit方法的具體用法?C# BigInteger.FlipBit怎麽用?C# BigInteger.FlipBit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BigInteger的用法示例。


在下文中一共展示了BigInteger.FlipBit方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TestFlipBit

        public void TestFlipBit()
        {
            for (int i = 0; i < 10; ++i)
            {
                var a = new BigInteger(128, 0, Rnd);
                BigInteger b = a;

                for (int x = 0; x < 100; ++x)
                {
                    // Note: Intentionally greater than initial size
                    int pos = Rnd.Next(256);

                    a = a.FlipBit(pos);
                    b = b.TestBit(pos) ? b.ClearBit(pos) : b.SetBit(pos);
                }

                Assert.AreEqual(a, b);
            }

            for (int i = 0; i < 100; ++i)
            {
                BigInteger pow2 = One.ShiftLeft(i);
                BigInteger minusPow2 = pow2.Negate();

                Assert.AreEqual(Zero, pow2.FlipBit(i));
                Assert.AreEqual(minusPow2.ShiftLeft(1), minusPow2.FlipBit(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.Xor(One.ShiftLeft(j)), bigI.FlipBit(j), data);
                    Assert.AreEqual(negI.Xor(One.ShiftLeft(j)), negI.FlipBit(j), data);
                }
            }
        }
開發者ID:ChemicalRocketeer,項目名稱:BigMath,代碼行數:38,代碼來源:BigIntegerTest.cs

示例2: FlipBit_pos_outside

 public void FlipBit_pos_outside()
 {
     BigInteger x = new BigInteger(1, 0xFFFF0000, 0xFFFF0000);
     BigInteger y = x.FlipBit(99);
     Expect(SameValue(y, 1, new uint[] { 8, 0, 0xFFFF0000, 0xFFFF0000 }));
 }
開發者ID:richhickey,項目名稱:clojure-clr,代碼行數:6,代碼來源:BigIntegerTests.cs

示例3: FlipBit_pos_inside_initial_set

 public void FlipBit_pos_inside_initial_set()
 {
     BigInteger x = new BigInteger(1, 0xFFFF0000, 0xFFFF0000);
     BigInteger w = new BigInteger(1, 0xFEFF0000, 0xFFFF0000);
     BigInteger y = x.FlipBit(56);
     Expect(y == w);
 }
開發者ID:richhickey,項目名稱:clojure-clr,代碼行數:7,代碼來源:BigIntegerTests.cs

示例4: FlipBit_pos_inside_initial_clear

 public void FlipBit_pos_inside_initial_clear()
 {
     BigInteger x = new BigInteger(1, 0xFFFF0000, 0xFFFF0000);
     BigInteger w = new BigInteger(1, 0xFFFF0080, 0xFFFF0000);
     BigInteger y = x.FlipBit(39);
     Expect(y == w);
 }
開發者ID:richhickey,項目名稱:clojure-clr,代碼行數:7,代碼來源:BigIntegerTests.cs

示例5: FlipBit_neg_inside_initial_set

 public void FlipBit_neg_inside_initial_set()
 {
     BigInteger x = new BigInteger(-1, 0xFFFF0000, 0xFFFF0000);
     BigInteger w = new BigInteger(-1, 0xFFFF0080, 0xFFFF0000);
     BigInteger y = x.FlipBit(39);
     Expect(y == w);
 }
開發者ID:richhickey,項目名稱:clojure-clr,代碼行數:7,代碼來源:BigIntegerTests.cs

示例6: FlipBit_neg_inside_initial_clear

 public void FlipBit_neg_inside_initial_clear()
 {
     BigInteger x = new BigInteger(-1, 0xFFFF0000, 0xFFFF0000);
     BigInteger w = new BigInteger(-1, 0xFEFF0000, 0xFFFF0000);
     BigInteger y = x.FlipBit(56);
     Expect(y == w);
 }
開發者ID:richhickey,項目名稱:clojure-clr,代碼行數:7,代碼來源:BigIntegerTests.cs


注:本文中的BigInteger.FlipBit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。