예제 #1
0
        private Result ProcessModuloMethod()
        {
            Result res = new Result();

            byte[]     binar    = new byte[BinaryNumber.Length + 1];
            BigInteger divisor  = new BigInteger();
            BigInteger dividend = new BigInteger();
            BigInteger bigres   = new BigInteger();

            try
            {
                divisor = new BigInteger(Math.Pow(10, settings.Quant));
            }
            catch (OverflowException e)
            {
                GuiLogMessage("Overflow Exception: Numbers to Big. Try again with smaller numbers", NotificationLevel.Error);
            }

            BinaryNumber.CopyTo(binar, 0);
            binar[binar.Length - 1] = 0x00;
            dividend = new BigInteger(binar);
            // Execute Modulo Operation
            bigres = BigInteger.Remainder(dividend, divisor);

            // BigInteger to Int[]
            res.Ires = bigIntegerToIntArray(bigres);
            res.Sres = bigres.ToString();

            return(res);
        }
예제 #2
0
        private Result ProcessMultMethod()
        {
            Result     res = new Result();
            BigInteger z, div = new BigInteger(), factor = new BigInteger(), bres;

            byte[] zbyte = new byte[BinaryNumber.Length + 1];

            // Calculate Result
            BinaryNumber.CopyTo(zbyte, 0);
            zbyte[zbyte.Length - 1] = 0x00;
            z = new BigInteger(zbyte);

            try
            {
                factor = new BigInteger(Math.Pow(10, settings.Quant));
                div    = new BigInteger(Math.Pow(2, 8 * BinaryNumber.Length));
            }
            catch (OverflowException e)
            {
                GuiLogMessage("Overflow Exception: Numbers to Big. Try again with smaller numbers.", NotificationLevel.Error);
            }
            bres = BigInteger.Multiply(z, factor);

            try
            {
                bres = BigInteger.Divide(bres, div);
            }
            catch (DivideByZeroException e)
            {
                GuiLogMessage("Overflow Exception: Numbers to Big. Try again with smaller numbers.", NotificationLevel.Error);
            }

            // Write Result to Return Structure
            res.Ires = bigIntegerToIntArray(bres);
            res.Sres = bres.ToString();

            return(res);
        }