java中16进制转换10进制
java中16进制转换10进制
public static void main(String[] args) { String str = "04e1"; String myStr[] = { "a", "b", "c", "d", "e", "f" }; int result = 0; int n = 1; for (int i = str.length() - 1; i >= 0; i--) { String param = str.substring(i, i + 1); for (int j = 0; j < myStr.length; j++) { if (param.equalsIgnoreCase(myStr[j])) { param = "1" + String.valueOf(j); } } result += Integer.parseInt(param) * n; n *= 16; } System.out.println(result); System.out.println(Integer.parseInt(str, 16)); }