Android hex十六进制转String

2017-09-28  本文已影响234人  ZZES_ZCDC

百度的都不好用,最后在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
上一篇下一篇

猜你喜欢

热点阅读