Convert number from one radix to another I am relatively new to coding and could use some help figuring out how I could improve my coding technique and habits. Here's an example of a working Java program I wrote that converts a number of some radix (from 2 to 36) to another radix (from 2 to 36).

Any tips or criticisms?

class RadixConverter {
    // command line arguments: (number) (radix of number) (radix to be converted to)
    public static void main(String[] args) {
        String n = args[0];                                   // n kept as String to support alphabetic representations of numerals for larger radixes
        int startRadix = Integer.parseInt(args[1]);
        int endRadix = Integer.parseInt(args[2]);
        int decimal = convertToDecimal(n, startRadix);
        String result = convertToBase(decimal, endRadix);
        System.out.printf("%s (%d) = %s (%d)%n", n, startRadix, result, endRadix);
    }

    public static int convertToDecimal(String n, int startRadix) {
        int sum = 0;
        for (int i = 0; i &lt; n.length(); i++) {                                                 // begins at first digit and ends at last digit
            char digit = n.charAt(i);
            int placeValue = (int) Math.pow(startRadix, n.length() - i - 1);                   // place value of digit's column
            if ((digit &gt;= 48) &amp;&amp; (digit &lt;= 57) &amp;&amp; (digit - 48 &lt; startRadix)) {                 // if digit is numerical and is within specified radix
                sum += (digit - 48) * placeValue;
            } else if ((digit &gt;= 65) &amp;&amp; (digit &lt;= 90) &amp;&amp; (digit - 65 + 10 &lt; startRadix)) {     // if digit is alphabetic and within specified radix
                sum += (digit - 55) * placeValue;
            } else {
                throw new IllegalArgumentException("\n\nThe input number is invalid or contains digits outside of its specified radix.\n");
            }
        }
        return sum;
    }

    public static String convertToBase(int decimal, int endRadix) {
        StringBuilder sb = new StringBuilder("");
        do {
            int rem = decimal % endRadix;
            if ((rem &lt;= 9) &amp;&amp; (endRadix &lt;= 36) &amp;&amp; (endRadix &gt;= 2)) {
                sb.append(Integer.toString(rem));
            } else if ((rem &lt;= 35) &amp;&amp; (endRadix &lt;= 36) &amp;&amp; (endRadix &gt;= 2)) {
                sb.append((char) (rem + 55));
            } else {
                throw new IllegalArgumentException("\n\nThe output radix must be from 2 to 36.\n");
            }
            decimal /= endRadix;
        } while (decimal != 0);
        return reverseOrder(sb.toString());
    }

    public static String reverseOrder(String s) {
        StringBuilder sb = new StringBuilder("");
        for (int i = s.length() - 1; i &gt;= 0; i--) {    // executes each character in reverse order
            sb.append(s.charAt(i));
        }
        return sb.toString();
    }
}
You're re-inventing the wheel. In the Integer class, there are methods for converting numbers to and from Strings with a radix parameter. So the following class does the job:

package test;

public class Test {

    public static void main(String[] args) {
        int inRadix = Integer.parseInt(args[1]);
        int outRadix = Integer.parseInt(args[2]);
        int value = Integer.parseInt(args[0], inRadix);
        String result = Integer.toString(value, outRadix);
        System.out.printf("%s (%d) = %s (%d)%n", value, inRadix, result, outRadix);
    }
}


But let's for a moment suppose the methods weren't there and look at your solution.

First, the method name convertToDecimal shows a (quite common, I have to say) mis-understanding. An int is internally represented in binary (radix 2), not decimal (radix 10). So convertToInt would be a better name.

I'd extract the character-versus-digit-value logic into methods int digitValueOf(char ch) and char digitCharFor(int digit) (By the way, the Character class has these methods).

I'd replace the numbers like 48 by the characters they represent (e.g. '0'). Not every reader knows the Unicode table by heart.

I'd replace the Math.pow() by consecutive integer multiplication. Turn the loop the other way round, starting from the last digit with placeValue = 1. In every iteration, multiply placeValue by radix. Math.pow() is slower and less exact than integer arithmetic.

I'd get into the habit of adding Javadoc even to trivial methods. After a year or so, you'll be happy.

Personally, I'm lazy with comments inside methods. A good method name, a Javadoc explaining what the method does (not how), and a straightforward implementation within the method are typically enough for a reader to understand what's going on.

Good is the usage of StringBuilder instead of concatenating Strings (quite common performance killer).

Good is throwing an exception in case of illegal characters.

Good is following the standard Java naming conventions.