daniel_lawson9999

Daniel Lawson Convert Program

Sep 1st, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. /**
  2.  * Created by danie on 9/1/2017.
  3.  */
  4. public class ConvertToBase {
  5.     public static void main(String args[]){
  6.         System.out.println(ConvertBinary(16,31513));
  7.     }
  8.     public static String ConvertBinary(int base, int number){
  9.         String out = "";
  10.         while(number != 0){
  11.             int mod = number % base;
  12.             String temp = GetValue(mod);
  13.             number /= base;
  14.             out = temp + out;
  15.         }
  16.         return out;
  17.     }
  18.     public static String GetValue(int n){
  19.         char values[] = {'A','B','C','D','E','F'};
  20.         if(n>=10){
  21.             return "" + values[n-10];
  22.         }
  23.         else{
  24.             return "" + n;
  25.         }
  26.  
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment