public class Hex2Dec {
public static void main(String[] args) {
long sum=0,tmp=0;
for(int i=0;i{
char c=args[0].charAt(i);
if(c>='0'&&c<='9')tmp=c-'0';
else if(c>='A'&&c<='F')tmp=c-'A'+10;
else {System.out.println("有非法字符");break;}
sum=sum*16+tmp;
}
System.out.println("十六进制"+args[0]+"===>十进制"+sum);
}
}
运行 java Hex2Dec 123ABCDEF
十六进制123ABCDEF===>十进制4893429231
public class ShiLiuToShi {
public static void main(String[] args) {
String s="ea";
int m=Integer.parseInt(s,16);
System.out.println(m);
}
}