Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1.     MyBigInteger base = new MyBigInteger(10);
  2.         base.coefficients.add(newBase);
  3.        
  4.         MyBigInteger oldBase = new MyBigInteger(this.base);
  5.         oldBase.coefficients.add(this.base);
  6.         //System.out.println(base);
  7.        
  8.         //   ADD YOUR CODE BELOW HERE
  9.        
  10.         MyBigInteger zero = new MyBigInteger(0, 10);
  11.         //System.out.println(zero);
  12.        
  13.         if(this.base!=10) { // Change base to 10
  14.             result.base=this.base;
  15.            
  16.            
  17.             int n = this.getCoefficients().size(); // Length of this
  18.             MyBigInteger temp = new MyBigInteger(this.base); // Temporary BigInt
  19.            
  20.            
  21.             for(int i=0; i<n; i++) {
  22.                
  23.                 temp.coefficients.add(this.getCoefficients().get(i));
  24.                
  25.                 // Adds coefficients of this to temp
  26.                
  27.                 System.out.println(temp+" - "+temp.timesBaseToThePower(i));
  28.                
  29.                 for(int j=0; j<=i; j++) {
  30.                     result=result.plus(temp.times(oldBase));
  31.                 }
  32.                
  33.                 //result=result.plus(temp.timesBaseToThePower(i));
  34.                 //System.out.println(result);
  35.                
  36.                 temp.coefficients.clear();
  37.             }
  38.            
  39.             result.base = 10;
  40.             //System.out.println(this+" In Base 10 "+result);
  41.            
  42.             this.base = 10;
  43.             this.coefficients=result.getCoefficients();
  44.             result.coefficients.clear();
  45.             result.base=newBase;
  46.            
  47.            
  48.         }
  49.        
  50.        
  51.        
  52.         while(this.compareTo(zero)!=0) { // change from 10 to new base
  53.                
  54.             result.coefficients.add(this.mod(base).getCoefficients().get(0));
  55.             // Adds number % base to results
  56.            
  57.             this.coefficients = this.dividedBy(base).coefficients;
  58.             // Number = Number / Base
  59.                
  60.             if(this.compareTo(empty)==0){
  61.                 //System.out.println("Empty");
  62.                 break;
  63.             }
  64.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement