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));
    }

 

posted @ 2014-01-12 14:10  努力挣扎的小兵  阅读(2659)  评论(1编辑  收藏  举报