public void TestFlipBit() { for (int i = 0; i < 10; ++i) { IBigInteger a = new BigInteger(128, 0, _random); IBigInteger b = a; for (int x = 0; x < 100; ++x) { // Note: Intentionally greater than initial size int pos = _random.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) { IBigInteger pow2 = one.ShiftLeft(i); IBigInteger minusPow2 = pow2.Negate(); Assert.AreEqual(zero, pow2.FlipBit(i)); Assert.AreEqual(minusPow2.ShiftLeft(1), minusPow2.FlipBit(i)); IBigInteger bigI = BigInteger.ValueOf(i); IBigInteger 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); } } }