public class Main { public static String tran1(int len,char chars[]){ String res=new String(); for(int i=0;i<len;i++){ if(chars[i]=='0'){ res=res+"0000"; } if(chars[i]=='1'){ res=res+"0001"; } if(chars[i]=='2'){ res=res+"0010"; } if(chars[i]=='3'){ res=res+"0011"; } if(chars[i]=='4'){ res=res+"0100"; } if(chars[i]=='5'){ res=res+"0101"; } if(chars[i]=='6'){ res=res+"0110"; } if(chars[i]=='7'){ res=res+"0111"; } if(chars[i]=='8'){ res=res+"1000"; } if(chars[i]=='9'){ res=res+"1001"; } if(chars[i]=='A'){ res=res+"1010"; } if(chars[i]=='B'){ res=res+"1011"; } if(chars[i]=='C'){ res=res+"1100"; } if(chars[i]=='D'){ res=res+"1101"; } if(chars[i]=='E'){ res=res+"1110"; } if(chars[i]=='F'){ res=res+"1111"; } } return res; } public static String sixteentotwo(String s){ String res= new String(); char chars[]=s.toCharArray(); res=tran1(s.length(),chars); return res; } public static int twototen(String s){ char chars[]=s.toCharArray(); int res=0; for(int index=0;index<s.length();index++){ res+=(chars[index]-'0')*Math.pow(2, s.length()-1-index); } return res; } public static int sixteentoten(String s){ return twototen(sixteentotwo(s)); } public static String ans(int num){ String res=String.valueOf(num); int zero=15-res.length(); for(int i=0;i<zero;i++){ res=" "+res; } return res; } public static void main(String[] args) throws Exception { String s="ABCDEF"; System.out.println(ans(sixteentoten(s))); //System.out.println("Hello, World!"); //System.out.printf("%15d",Integer.parseInt(s,16)); } }