public class Test {
final static int JINZHI=16; public static void main(String[] args) { String ten="1111"; String n="457"; System.out.println("10进制:"+ten+"-------------------"+JINZHI+"进制:"+tenToN(ten)); System.out.println(JINZHI+"进制:"+n+"-------------------10进制:"+nToTen(n)); } private static String nToTen(String n){ int ten =0; for(int i=0;i<n.length();i++){ ten=(int) (ten+Integer.parseInt(""+n.charAt(i))*(Math.pow(JINZHI,n.length()-i-1))); } return Integer.toString(ten); } private static String tenToN(String ten){ StringBuilder n = new StringBuilder(); while(Integer.parseInt(ten)/JINZHI>=1){ n.append(Integer.parseInt(ten)%JINZHI); ten=Integer.toString(Integer.parseInt(ten)/JINZHI); } n.append(Integer.parseInt(ten)%JINZHI); return n.reverse().toString(); }}