Example #1
0
        public static BigInteger2[] DivideBy(BigInteger2 Numb1, BigInteger2 Numb2)
        {
            var numb1 = BigInteger2.GetBytesTwosCompliment(Numb1);
            var numb2 = BigInteger2.GetBytesTwosCompliment(Numb2);

            BigInteger n1 = new BigInteger(numb1);
            BigInteger n2 = new BigInteger(numb2);
            BigInteger quot;
            BigInteger result = BigInteger.DivRem(n1, n2, out quot);

            BigInteger2[] results = new BigInteger2[2];

            var bitAry = BigInteger2.ReverseBigIntegerBitsToBitArray(result.ToByteArray());
            var whole  = new BigInteger2(bitAry.Length, 0);

            BigInteger2.CopyFromBitArrayFromIndex(bitAry, whole, 0);

            var bitAry2  = BigInteger2.ReverseBigIntegerBitsToBitArray(quot.ToByteArray());
            var quotient = new BigInteger2(bitAry2.Length, 0);

            BigInteger2.CopyFromBitArrayFromIndex(bitAry2, quotient, 0);

            results[0] = BigInteger2.NegateZeros(whole);
            results[1] = BigInteger2.NegateZeros(quotient);

            return(results);
        }
Example #2
0
        public static BigInteger2 gcd(BigInteger2 Numb1, BigInteger2 Numb2)
        {
            var numb1 = BigInteger2.GetBytesTwosCompliment(Numb1);
            var numb2 = BigInteger2.GetBytesTwosCompliment(Numb2);

            BigInteger n1 = new BigInteger(numb1);
            BigInteger n2 = new BigInteger(numb2);

            var result = BigInteger.GreatestCommonDivisor(n1, n2);

            var bitAry = BigInteger2.ReverseBigIntegerBitsToBitArray(result.ToByteArray());
            var whole  = new BigInteger2(bitAry.Length, 0);

            BigInteger2.CopyFromBitArrayFromIndex(bitAry, whole, 0);
            return(BigInteger2.NegateZeros(whole));
        }
Example #3
0
        public static BigInteger2 modPower(BigInteger2 current, BigInteger2 power, BigInteger2 mod)
        {
            var numb1 = BigInteger2.GetBytesTwosCompliment(current);
            var numb2 = BigInteger2.GetBytesTwosCompliment(power);
            var numb3 = BigInteger2.GetBytesTwosCompliment(mod);

            BigInteger n1 = new BigInteger(numb1);
            BigInteger n2 = new BigInteger(numb2);
            BigInteger n3 = new BigInteger(numb3);

            var result = BigInteger.ModPow(n1, n2, n3);

            var bitAry = BigInteger2.ReverseBigIntegerBitsToBitArray(result.ToByteArray());
            var whole  = new BigInteger2(bitAry.Length, 0);

            BigInteger2.CopyFromBitArrayFromIndex(bitAry, whole, 0);

            return(BigInteger2.NegateZeros(whole));
        }