using System; using System.Collections; using System.Windows.Forms; namespace Science.Mathematics.Calculus { /// /// int is the same as Integer. /// public class Integer { private int x; public Integer(int n) { x = n; bbase = 10; } private int bbase; public int Base { get{return bbase;} set { bbase=value; if(bbase > 36) try{throw new Exception();} catch (Exception) { MessageBox.Show("Too big base, Base should be less than or equal to 36.", "Invalid Input",MessageBoxButtons.OK, MessageBoxIcon.Error ); } } } public char[] IntegerDigits { get { if(bbase == 10) { char[] res; string s = x.ToString(); res = s.ToCharArray(); return res; } else { int temp = x, xx; char cx = '0'; ArrayList al = new ArrayList(1); while(temp != 0) { xx = temp % bbase; temp = (temp - xx)/bbase; if(xx < 10) al.Add(xx); else { if(xx == 10) cx = 'A'; else if(xx == 11) cx = 'B'; else if(xx == 12) cx = 'C'; else if(xx == 13) cx = 'D'; else if(xx == 14) cx = 'E'; else if(xx == 15) cx = 'F'; else if(xx == 16) cx = 'G'; else if(xx == 17) cx = 'H'; else if(xx == 18) cx = 'I'; else if(xx == 19) cx = 'J'; else if(xx == 20) cx = 'K'; else if(xx == 21) cx = 'L'; else if(xx == 22) cx = 'M'; else if(xx == 23) cx = 'N'; else if(xx == 24) cx = 'O'; else if(xx == 25) cx = 'P'; else if(xx == 26) cx = 'Q'; else if(xx == 27) cx = 'R'; else if(xx == 28) cx = 'S'; else if(xx == 29) cx = 'T'; else if(xx == 30) cx = 'U'; else if(xx == 31) cx = 'V'; else if(xx == 32) cx = 'W'; else if(xx == 33) cx = 'X'; else if(xx == 34) cx = 'Y'; else cx = 'Z'; al.Add(cx); } } char[] res = new char[al.Count]; for(int j = 0; j < al.Count; j++) { res[j] = Convert.ToChar(Convert.ToString(al[j])); } return res; } } } public int IntegerExponent(int b) //the highest power of b that divides n. { int n = 0, temp = x, mmod; mmod = temp % b; while(mmod == 0) { n++; temp /= b; mmod = temp % b; } return n; } } }