예제 #1
0
        private string multiplyValue(Integer value, string original)
        {
            ArrayList answers = new ArrayList( );

            for (int i = 0; i < value.Value.Length; i++)
            {
                Integer currAns = new Integer( );
                // prepend zeroes
                currAns.Value = "";
                currAns.Value.PadRight(i, '0');
                for (int x = 0; x < i; x++)
                {
                    currAns.Value += "0";
                }

                int carry = 0;
                for (int j = original.Length; j != 0; j--)
                {
                    int result = (int.Parse(value.Value.Substring(value.Value.Length - (i + 1), 1)) * int.Parse(original.Substring(j - 1, 1))) + carry;

                    string resultstr = result.ToString( );

                    if (resultstr.Length > 1)
                    {
                        carry     = int.Parse(resultstr.Substring(0, resultstr.Length - 1));
                        resultstr = resultstr.Substring(resultstr.Length - 1);
                    }
                    else
                    {
                        carry = 0;
                    }
                    currAns.Value = resultstr + currAns.Value;
                }
                currAns.Value = carry + currAns.Value;
                answers.Add(currAns);
            }

            Integer export = new Integer( );

            export.Value = "0";
            foreach (Integer item in answers)
            {
                export.add(item);
            }
            return(trim(export.Value));
        }
예제 #2
0
        /// <summary>
        /// divides this number by provided divisor number, result stored by this number.
        /// </summary>
        /// <param name="divisor"></param>
        /// <returns>remainder</returns>
        public Integer slowDivide(Integer divisor)
        {
            Integer counter     = new Integer( );
            Integer incrementor = new Integer( );

            incrementor.Value = "1";
            counter.Value     = "0";
            while (isBiggerThan(divisor))
            {
                counter.add(incrementor);
                this.subtract(divisor);
            }
            Integer remainder = new Integer( );

            remainder.Value = store;
            store           = counter.Value;
            return(remainder);
        }
예제 #3
0
        private string multiplyValue( Integer value, string original )
        {
            ArrayList answers = new ArrayList( );
            for( int i = 0; i < value.Value.Length; i++ )
            {
                Integer currAns = new Integer( );
                // prepend zeroes
                currAns.Value = "";
                currAns.Value.PadRight( i, '0' );
                for( int x = 0; x < i; x++ )
                {
                    currAns.Value += "0";
                }

                int carry = 0;
                for( int j = original.Length; j != 0; j-- )
                {
                    int result = ( int.Parse( value.Value.Substring( value.Value.Length - ( i + 1 ), 1 ) ) * int.Parse( original.Substring( j - 1, 1 ) ) ) + carry;

                    string resultstr = result.ToString( );

                    if( resultstr.Length > 1 )
                    {
                        carry = int.Parse( resultstr.Substring( 0, resultstr.Length - 1 ) );
                        resultstr = resultstr.Substring( resultstr.Length - 1 );
                    }
                    else
                    {
                        carry = 0;
                    }
                    currAns.Value = resultstr + currAns.Value;
                }
                currAns.Value = carry + currAns.Value;
                answers.Add( currAns );

            }

            Integer export = new Integer( );
            export.Value = "0";
            foreach( Integer item in answers )
            {
                export.add( item );
            }
            return trim( export.Value );
        }
예제 #4
0
 /// <summary>
 /// divides this number by provided divisor number, result stored by this number.
 /// </summary>
 /// <param name="divisor"></param>
 /// <returns>remainder</returns>
 public Integer slowDivide( Integer divisor )
 {
     Integer counter = new Integer( );
     Integer incrementor = new Integer( );
     incrementor.Value = "1";
     counter.Value = "0";
     while( isBiggerThan( divisor ) )
     {
         counter.add( incrementor );
         this.subtract( divisor );
     }
     Integer remainder = new Integer( );
     remainder.Value = store;
     store = counter.Value;
     return remainder;
 }