Skip to content

Instantly share code, notes, and snippets.

@blazindragon
Created January 22, 2014 09:22
Show Gist options
  • Select an option

  • Save blazindragon/8555830 to your computer and use it in GitHub Desktop.

Select an option

Save blazindragon/8555830 to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
public class BaseConversion {
public static void main(String...z) {
if (z.length !=2) {
System.out.printf("Usage: java BaseConversion <integer> <base>\n");
System.exit(1);
}
ArrayList<Integer> result = new ArrayList<Integer>();
int num = Integer.parseInt(z[0]);
int base = Integer.parseInt(z[1]);
int remainder = 0;
while (num !=0) {
remainder = num % base;
num = num / base;
result.add(remainder);
}
String res = "";
for (int i = result.size() - 1; i >= 0; --i) {
res += result.get(i);
}
System.out.printf("%s to %s = %s\n", z[0], z[1], res);
}
}
@majinmartin93
Copy link

Yo, do you have skype? how can i contact you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment