I am trying to convert a base 10 number to any base by using conversion. Right now this is the code I have came up with. I have a sad feeling this may be completely wrong. The image below is an example of how this process should take place.
http://i854.photobucket.com/albums/ab107/tonytauart/rrrr.png
public static void main(String[] args) {
int base;
int number;
Scanner console = new Scanner(System.in);
System.out.println("Please enter the base");
base = console.nextInt();
System.out.println("Please enter the Number you would like to convert");
number = console.nextInt();
System.out.println(Converter(base, number));
}
public static int Converter(int Nbase, int Nnumber){
int answer;
int Rcontainer =0;
int cnt = 0;
int multiplier;
int temp;
double exp;
if(Nnumber/Nbase == 0){
cnt++;
exp = Math.pow(10,cnt);
multiplier = (int)exp;
answer = (Nnumber%Nbase)* multiplier + Rcontainer;
}
else
{
exp = Math.pow(10,cnt);
multiplier = (int)exp;
cnt++;
temp = Rcontainer;
Rcontainer = (Nnumber%Nbase)* multiplier + temp;
Nnumber = Nnumber/Nbase;
answer = Converter(Nbase,Nnumber);
}
return answer;
}
}