JAvaにおける16進変換10進法

1655 ワード

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

 
転載先:https://www.cnblogs.com/gavinYang/p/3515912.html