Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by danie on 9/1/2017.
- */
- public class ConvertToBase {
- public static void main(String args[]){
- System.out.println(ConvertBinary(16,31513));
- }
- public static String ConvertBinary(int base, int number){
- String out = "";
- while(number != 0){
- int mod = number % base;
- String temp = GetValue(mod);
- number /= base;
- out = temp + out;
- }
- return out;
- }
- public static String GetValue(int n){
- char values[] = {'A','B','C','D','E','F'};
- if(n>=10){
- return "" + values[n-10];
- }
- else{
- return "" + n;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment