Arithmetic Class

Project : Numbers.




 
//C#
// This class converts a number alphabet based in Base-N to 10 Base and viceversa. 
 
    public class Arithmetic 
    {
 
        public String ToNumber(int n, Alphabet a, int size)
        {
            String number = ToNumber(n, a);
            return number.Length>=size ? number : number.PadLeft(size,a.Alpabeth[0].ToCharArray()[0] ) ;
        }
 
        public String ToNumber(int n , Alphabet a)
        {
            String number = "";
            Logger.Log(" ");
            int k = n;
            while (k >= a.Base )
            {
                int mod = k % a.Base;
                int part = k / a.Base;
                Logger.Debug("  "+ n + " / " + a.Base + " = "  + part + " , mod =" + mod);
                number = a.Alpabeth[mod] + number ;
                k = part;
            }
 
            number = a.Alpabeth[k] + number ;
            Logger.Debug( n+ "(10) = " + number+"("+ a.Base +") ");
 
            return number;
 
        }
 
        public long ToNumber(Alphabet a , String value)
        {
            // Convert from any Base (designated by alphabet) to Integer(10) 
            int[] numeric = new int[10];
            int i = 0;
            Logger.Log(" " + value);
            long sum = 0; 
            while (i < value.Length ){
                i = i + 1;
                String symbol = value.Substring(value.Length - i, 1);
                long unity = a.Value[symbol] * ((long)Math.Pow(  a.Base , (i - 1)));
                sum = sum + unity;
                Logger.Debug(" Poss: (" + i + ") , Base(" + a.Base + ") " + symbol + " # Human symbol("+ symbol +"="+ a.Value[symbol] +") -> ("+symbol+"*(" + a.Base+ "^"+(i-1)+") ) = "+ unity);
            }
            Logger.Key();
            return sum;
        }
 
        public double Log(double number, double log_base)
        {
            double r = Math.Log(number, log_base);
            Logger.Log("---------------------------------------------------------------------");
            Logger.Log("| Log " + "".PadLeft((int)(Math.Log10(log_base)), ' ') + "(" + number + ")=" + r);
            Logger.Log("|    " + log_base + " ");
            Logger.Log("---------------------------------------------------------------------");
            return r;
        }
    }
 
 

Updated at: 20180120
by TALF Colombia.(R) 2018