字符串转Hex编码

public static String toHex(String str){
        try {
            byte[] bytes = str.getBytes("GBK");
            StringBuilder sb = new StringBuilder(bytes.length * 2);
            //转换hex编码
            for (byte b : bytes) {
                sb.append(Integer.toHexString(b + 0x800).substring(1));
            }
            return sb.toString();
        } catch (UnsupportedEncodingException e) {
            log.error(e);
        }
        return null;
    }

 

posted @ 2015-06-12 16:11  龙昭羽  阅读(3028)  评论(0编辑  收藏  举报