美文网首页
Android hex十六进制转String

Android hex十六进制转String

作者: ZZES_ZCDC | 来源:发表于2017-09-28 22:59 被阅读234次

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

    相关文章

      网友评论

          本文标题:Android hex十六进制转String

          本文链接:https://www.haomeiwen.com/subject/lnqbextx.html