Android hex十六进制转String

时间:2022-07-23
本文章向大家介绍Android hex十六进制转String,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

百度的都不好用,最后在stackoverflow上找到了。。。 https://stackoverflow.com/questions/12039341/hex-to-string-in-java-performance-is-too-slow

    public static String hexToString(String hex) {
        StringBuilder sb = new StringBuilder();
        for (int count = 0; count < hex.length() - 1; count += 2) {
            String output = hex.substring(count, (count + 2));    //grab the hex in pairs
            int decimal = Integer.parseInt(output, 16);    //convert hex to decimal
            sb.append((char) decimal);    //convert the decimal to character
        }
        return sb.toString();
    }

图片.png

图片.png