public void EmptyBigUIntNET() { var biguint = new BigUInt(); Assert.AreEqual(0, biguint.BitCount); Assert.AreEqual(0ul, biguint.ByteCount); Assert.AreEqual(0ul, biguint.UInt64Count); Assert.IsTrue(biguint.UInt64Count == 0ul); Assert.AreEqual(0, biguint.GetSignificantBitCount()); Assert.AreEqual("0", biguint.ToString()); Assert.IsTrue(biguint.IsZero); Assert.IsFalse(biguint.IsAlias); biguint.SetZero(); var biguint2 = new BigUInt(); Assert.IsTrue(biguint.Equals(biguint2)); biguint.Resize(1); Assert.AreEqual(1, biguint.BitCount); Assert.IsTrue(biguint.UInt64Count != 0ul); Assert.IsFalse(biguint.IsAlias); biguint.Resize(0); Assert.AreEqual(0, biguint.BitCount); Assert.IsTrue(biguint.UInt64Count == 0ul); Assert.IsFalse(biguint.IsAlias); }
public void ParseTest() { Random random = new Random(1234); for (int i = 0; i <= 2500; i++) { UInt32[] mantissa = UIntUtil.Random(random, BigUInt <Pow2.N16> .Length, random.Next(BigUInt <Pow2.N16> .Bits + 1)); BigUInt <Pow2.N16> v = new BigUInt <Pow2.N16>(mantissa, enable_clone: false); BigUInt <Pow2.N16> v2 = new BigUInt <Pow2.N16>(v.ToString()); Assert.AreEqual(v, v2); } for (int i = 0; i <= 2500; i++) { UInt32[] mantissa = UIntUtil.Random(random, BigUInt <Pow2.N32> .Length, random.Next(BigUInt <Pow2.N32> .Bits + 1)); BigUInt <Pow2.N32> v = new BigUInt <Pow2.N32>(mantissa, enable_clone: false); BigUInt <Pow2.N32> v2 = new BigUInt <Pow2.N32>(v.ToString()); Assert.AreEqual(v, v2); } for (int i = 0; i <= 2500; i++) { UInt32[] mantissa = UIntUtil.Random(random, BigUInt <Pow2.N64> .Length, random.Next(BigUInt <Pow2.N64> .Bits + 1)); BigUInt <Pow2.N64> v = new BigUInt <Pow2.N64>(mantissa, enable_clone: false); BigUInt <Pow2.N64> v2 = new BigUInt <Pow2.N64>(v.ToString()); Assert.AreEqual(v, v2); } }
public void ToStringFullTest() { BigUInt <Pow2.N32> v = BigUInt <Pow2.N32> .Full; BigInteger bi = v; Assert.AreEqual(bi.ToString(), v.ToString()); Console.WriteLine(v); }
static void Main(string[] args) { StreamReader sin = File.OpenText("numbers.txt"); BigUInt answer = new BigUInt(0); string number = sin.ReadLine(); while (!string.IsNullOrEmpty(number)) { answer = answer.Add(new BigUInt(number)); number = sin.ReadLine(); } sin.Close(); Console.Out.WriteLine(answer.ToString()); Console.Out.WriteLine("Klaar"); Console.In.ReadLine(); }
public void ParseFullTest() { { BigUInt <Pow2.N16> v = BigUInt <Pow2.N16> .Full; BigUInt <Pow2.N16> v2 = new BigUInt <Pow2.N16>(v.ToString()); Assert.AreEqual(v, v2); } { BigUInt <Pow2.N32> v = BigUInt <Pow2.N32> .Full; BigUInt <Pow2.N32> v2 = new BigUInt <Pow2.N32>(v.ToString()); Assert.AreEqual(v, v2); } { BigUInt <Pow2.N64> v = BigUInt <Pow2.N64> .Full; BigUInt <Pow2.N64> v2 = new BigUInt <Pow2.N64>(v.ToString()); Assert.AreEqual(v, v2); } }
public void ToStringTest() { Random random = new Random(1234); for (int i = 0; i <= 2500; i++) { UInt32[] mantissa = UIntUtil.Random( random, BigUInt <Pow2.N32> .Length, random.Next(BigUInt <Pow2.N32> .Bits + 1) ); BigUInt <Pow2.N32> v = new BigUInt <Pow2.N32>(mantissa, enable_clone: false); BigInteger bi = v; Assert.AreEqual(bi.ToString(), v.ToString()); Console.WriteLine(v); } }
public void BigUInt99BitsNET() { var biguint = new BigUInt(99); Assert.AreEqual(99, biguint.BitCount); Assert.IsTrue(biguint.UInt64Count != 0ul); Assert.AreEqual(13ul, biguint.ByteCount); Assert.AreEqual(2ul, biguint.UInt64Count); Assert.AreEqual(0, biguint.GetSignificantBitCount()); Assert.AreEqual("0", biguint.ToString()); Assert.IsTrue(biguint.IsZero); Assert.AreEqual(0UL, biguint.Data(0)); Assert.AreEqual(0UL, biguint.Data(1)); Assert.AreEqual(0, biguint[0]); Assert.AreEqual(0, biguint[1]); Assert.AreEqual(0, biguint[2]); Assert.AreEqual(0, biguint[3]); Assert.AreEqual(0, biguint[4]); Assert.AreEqual(0, biguint[5]); Assert.AreEqual(0, biguint[6]); Assert.AreEqual(0, biguint[7]); Assert.AreEqual(0, biguint[8]); Assert.AreEqual(0, biguint[9]); Assert.AreEqual(0, biguint[10]); Assert.AreEqual(0, biguint[11]); Assert.AreEqual(0, biguint[12]); biguint.Set(1); Assert.AreEqual(1, biguint.GetSignificantBitCount()); Assert.AreEqual("1", biguint.ToString()); Assert.IsFalse(biguint.IsZero); Assert.AreEqual(13ul, biguint.ByteCount); Assert.AreEqual(2ul, biguint.UInt64Count); Assert.AreEqual(1UL, biguint.Data(0)); Assert.AreEqual(0UL, biguint.Data(1)); Assert.AreEqual(1, biguint[0]); Assert.AreEqual(0, biguint[1]); Assert.AreEqual(0, biguint[2]); Assert.AreEqual(0, biguint[3]); Assert.AreEqual(0, biguint[4]); Assert.AreEqual(0, biguint[5]); Assert.AreEqual(0, biguint[6]); Assert.AreEqual(0, biguint[7]); Assert.AreEqual(0, biguint[8]); Assert.AreEqual(0, biguint[9]); Assert.AreEqual(0, biguint[10]); Assert.AreEqual(0, biguint[11]); Assert.AreEqual(0, biguint[12]); biguint.SetZero(); Assert.IsTrue(biguint.IsZero); Assert.AreEqual(0UL, biguint.Data(0)); Assert.AreEqual(0UL, biguint.Data(1)); biguint.Set("7FFFFFFFFFFFFFFFFFFFFFFFF"); Assert.AreEqual(99, biguint.GetSignificantBitCount()); Assert.AreEqual("7FFFFFFFFFFFFFFFFFFFFFFFF", biguint.ToString()); Assert.IsFalse(biguint.IsZero); Assert.AreEqual(0xFFFFFFFFFFFFFFFFUL, biguint.Data(0)); Assert.AreEqual(0x7FFFFFFFFUL, biguint.Data(1)); Assert.AreEqual(0xFF, biguint[0]); Assert.AreEqual(0xFF, biguint[1]); Assert.AreEqual(0xFF, biguint[2]); Assert.AreEqual(0xFF, biguint[3]); Assert.AreEqual(0xFF, biguint[4]); Assert.AreEqual(0xFF, biguint[5]); Assert.AreEqual(0xFF, biguint[6]); Assert.AreEqual(0xFF, biguint[7]); Assert.AreEqual(0xFF, biguint[8]); Assert.AreEqual(0xFF, biguint[9]); Assert.AreEqual(0xFF, biguint[10]); Assert.AreEqual(0xFF, biguint[11]); Assert.AreEqual(0x07, biguint[12]); biguint.SetZero(); Assert.IsTrue(biguint.IsZero); Assert.AreEqual(0UL, biguint.Data(0)); Assert.AreEqual(0UL, biguint.Data(1)); biguint.Set("4000000000000000000000000"); Assert.AreEqual(99, biguint.GetSignificantBitCount()); Assert.AreEqual("4000000000000000000000000", biguint.ToString()); Assert.IsFalse(biguint.IsZero); Assert.AreEqual(0UL, biguint.Data(0)); Assert.AreEqual(0x400000000UL, biguint.Data(1)); Assert.AreEqual(0, biguint[0]); Assert.AreEqual(0, biguint[1]); Assert.AreEqual(0, biguint[2]); Assert.AreEqual(0, biguint[3]); Assert.AreEqual(0, biguint[4]); Assert.AreEqual(0, biguint[5]); Assert.AreEqual(0, biguint[6]); Assert.AreEqual(0, biguint[7]); Assert.AreEqual(0, biguint[8]); Assert.AreEqual(0, biguint[9]); Assert.AreEqual(0, biguint[10]); Assert.AreEqual(0, biguint[11]); Assert.AreEqual(0x04, biguint[12]); biguint.Set(0x8001); Assert.AreEqual(16, biguint.GetSignificantBitCount()); Assert.AreEqual("8001", biguint.ToString()); Assert.IsFalse(biguint.IsZero); Assert.AreEqual(0x8001UL, biguint.Data(0)); Assert.AreEqual(0UL, biguint.Data(1)); Assert.AreEqual(0x01, biguint[0]); Assert.AreEqual(0x80, biguint[1]); Assert.AreEqual(0, biguint[2]); Assert.AreEqual(0, biguint[3]); Assert.AreEqual(0, biguint[4]); Assert.AreEqual(0, biguint[5]); Assert.AreEqual(0, biguint[6]); Assert.AreEqual(0, biguint[7]); Assert.AreEqual(0, biguint[8]); Assert.AreEqual(0, biguint[9]); Assert.AreEqual(0, biguint[10]); Assert.AreEqual(0, biguint[11]); Assert.AreEqual(0, biguint[12]); var biguint2 = new BigUInt("123"); Assert.IsFalse(biguint.Equals(biguint2)); Assert.IsFalse(biguint2.Equals(biguint)); Assert.AreNotEqual(biguint.GetHashCode(), biguint2.GetHashCode()); biguint.Set(biguint2); Assert.IsTrue(biguint.Equals(biguint2)); Assert.IsTrue(biguint2.Equals(biguint)); Assert.AreEqual(biguint.GetHashCode(), biguint2.GetHashCode()); Assert.AreEqual(9, biguint.GetSignificantBitCount()); Assert.AreEqual("123", biguint.ToString()); Assert.AreEqual(0x123UL, biguint.Data(0)); Assert.AreEqual(0UL, biguint.Data(1)); Assert.AreEqual(0x23, biguint[0]); Assert.AreEqual(0x01, biguint[1]); Assert.AreEqual(0, biguint[2]); Assert.AreEqual(0, biguint[3]); Assert.AreEqual(0, biguint[4]); Assert.AreEqual(0, biguint[5]); Assert.AreEqual(0, biguint[6]); Assert.AreEqual(0, biguint[7]); Assert.AreEqual(0, biguint[8]); Assert.AreEqual(0, biguint[9]); Assert.AreEqual(0, biguint[10]); Assert.AreEqual(0, biguint[11]); Assert.AreEqual(0, biguint[12]); biguint.Resize(8); Assert.AreEqual(8, biguint.BitCount); Assert.AreEqual(1ul, biguint.UInt64Count); Assert.AreEqual("23", biguint.ToString()); biguint.Resize(100); Assert.AreEqual(100, biguint.BitCount); Assert.AreEqual(2ul, biguint.UInt64Count); Assert.AreEqual("23", biguint.ToString()); biguint.Resize(0); Assert.AreEqual(0, biguint.BitCount); Assert.AreEqual(0ul, biguint.UInt64Count); Assert.IsTrue(biguint.UInt64Count == 0); }
public void BigUInt64BitsNET() { var biguint = new BigUInt(64); Assert.AreEqual(64, biguint.BitCount); Assert.AreEqual(8ul, biguint.ByteCount); Assert.AreEqual(1ul, biguint.UInt64Count); Assert.AreEqual(0, biguint.GetSignificantBitCount()); Assert.AreEqual("0", biguint.ToString()); Assert.IsTrue(biguint.IsZero); Assert.IsTrue(biguint.UInt64Count != 0); Assert.AreEqual(0UL, biguint.Data(0)); Assert.AreEqual(0, biguint[0]); Assert.AreEqual(0, biguint[1]); Assert.AreEqual(0, biguint[2]); Assert.AreEqual(0, biguint[3]); Assert.AreEqual(0, biguint[4]); Assert.AreEqual(0, biguint[5]); Assert.AreEqual(0, biguint[6]); Assert.AreEqual(0, biguint[7]); biguint.Set(1); Assert.AreEqual(1, biguint.GetSignificantBitCount()); Assert.AreEqual("1", biguint.ToString()); Assert.IsFalse(biguint.IsZero); Assert.AreEqual(1UL, biguint.Data(0)); Assert.AreEqual(1, biguint[0]); Assert.AreEqual(0, biguint[1]); Assert.AreEqual(0, biguint[2]); Assert.AreEqual(0, biguint[3]); Assert.AreEqual(0, biguint[4]); Assert.AreEqual(0, biguint[5]); Assert.AreEqual(0, biguint[6]); Assert.AreEqual(0, biguint[7]); biguint.SetZero(); Assert.IsTrue(biguint.IsZero); Assert.AreEqual(0UL, biguint.Data(0)); biguint.Set("7FFFFFFFFFFFFFFF"); Assert.AreEqual(63, biguint.GetSignificantBitCount()); Assert.IsFalse(biguint.IsZero); Assert.AreEqual("7FFFFFFFFFFFFFFF", biguint.ToString()); Assert.AreEqual(0x7FFFFFFFFFFFFFFFUL, biguint.Data(0)); Assert.AreEqual(0xFF, biguint[0]); Assert.AreEqual(0xFF, biguint[1]); Assert.AreEqual(0xFF, biguint[2]); Assert.AreEqual(0xFF, biguint[3]); Assert.AreEqual(0xFF, biguint[4]); Assert.AreEqual(0xFF, biguint[5]); Assert.AreEqual(0xFF, biguint[6]); Assert.AreEqual(0x7F, biguint[7]); biguint.Set("FFFFFFFFFFFFFFFF"); Assert.AreEqual(64, biguint.GetSignificantBitCount()); Assert.IsFalse(biguint.IsZero); Assert.AreEqual("FFFFFFFFFFFFFFFF", biguint.ToString()); Assert.AreEqual(0xFFFFFFFFFFFFFFFFUL, biguint.Data(0)); Assert.AreEqual(0xFF, biguint[0]); Assert.AreEqual(0xFF, biguint[1]); Assert.AreEqual(0xFF, biguint[2]); Assert.AreEqual(0xFF, biguint[3]); Assert.AreEqual(0xFF, biguint[4]); Assert.AreEqual(0xFF, biguint[5]); Assert.AreEqual(0xFF, biguint[6]); Assert.AreEqual(0xFF, biguint[7]); biguint.Set(0x8001); Assert.AreEqual(16, biguint.GetSignificantBitCount()); Assert.AreEqual("8001", biguint.ToString()); Assert.AreEqual(0x8001UL, biguint.Data(0)); Assert.AreEqual(0x01, biguint[0]); Assert.AreEqual(0x80, biguint[1]); Assert.AreEqual(0x00, biguint[2]); Assert.AreEqual(0x00, biguint[3]); Assert.AreEqual(0x00, biguint[4]); Assert.AreEqual(0x00, biguint[5]); Assert.AreEqual(0x00, biguint[6]); Assert.AreEqual(0x00, biguint[7]); }
public void ExponentiateUIntNET() { int exponent; var bigUInt = new BigUInt(); var expUInt = new BigUInt(); exponent = 0; bigUInt.Set("1"); expUInt = Utilities.ExponentiateUInt(bigUInt, exponent); Assert.IsTrue(expUInt.ToString() == "1"); exponent = 0; bigUInt.Set("A123"); expUInt = Utilities.ExponentiateUInt(bigUInt, exponent); Assert.IsTrue(expUInt.ToString() == "1"); exponent = 0; bigUInt.Set("1234567890ABCDEF"); expUInt = Utilities.ExponentiateUInt(bigUInt, exponent); Assert.IsTrue(expUInt.ToString() == "1"); exponent = 1; bigUInt.Set("0"); expUInt = Utilities.ExponentiateUInt(bigUInt, exponent); Assert.IsTrue(expUInt.ToString() == "0"); exponent = 1; bigUInt.Set("1"); expUInt = Utilities.ExponentiateUInt(bigUInt, exponent); Assert.IsTrue(expUInt.ToString() == "1"); exponent = 1; bigUInt.Set("A123"); expUInt = Utilities.ExponentiateUInt(bigUInt, exponent); Assert.IsTrue(expUInt.ToString() == "A123"); exponent = 1; bigUInt.Set("1234567890ABCDEF"); expUInt = Utilities.ExponentiateUInt(bigUInt, exponent); Assert.IsTrue(expUInt.ToString() == "1234567890ABCDEF"); exponent = 2; bigUInt.Set("0"); expUInt = Utilities.ExponentiateUInt(bigUInt, exponent); Assert.IsTrue(expUInt.ToString() == "0"); exponent = 2; bigUInt.Set("1"); expUInt = Utilities.ExponentiateUInt(bigUInt, exponent); Assert.IsTrue(expUInt.ToString() == "1"); exponent = 2; bigUInt.Set("A123"); expUInt = Utilities.ExponentiateUInt(bigUInt, exponent); Assert.IsTrue(expUInt.ToString() == "656D0AC9"); exponent = 2; bigUInt.Set("1234567890ABCDEF"); expUInt = Utilities.ExponentiateUInt(bigUInt, exponent); Assert.IsTrue(expUInt.ToString() == "14B66DC328828BCA6475F09A2F2A521"); exponent = 123; bigUInt.Set("0"); expUInt = Utilities.ExponentiateUInt(bigUInt, exponent); Assert.IsTrue(expUInt.ToString() == "0"); exponent = 123; bigUInt.Set("1"); expUInt = Utilities.ExponentiateUInt(bigUInt, exponent); Assert.IsTrue(expUInt.ToString() == "1"); exponent = 123; bigUInt.Set("5"); expUInt = Utilities.ExponentiateUInt(bigUInt, exponent); Assert.IsTrue(expUInt.ToString() == "30684B4BF0E5E24DC014B5AC590720EB9AD08D8DF6046110F8F5AF53B8A61F969267EC1D"); }