16进制字符串和ascii字符串转换

  • Post author:
  • Post category:其他


	/**
     * 16进制字符串转ascii字符串
     * 如:30303030323032333636363637373737 == 0000202366667777
     *
     * @param hex
     * @return
     */
    public static String hexToAsciis(String hex) {
        StringBuilder output = new StringBuilder("");
        for (int i = 0; i < hex.length(); i += 2) {
            String str = hex.substring(i, i + 2);
            output.append((char) Integer.parseInt(str, 16));
        }
        return output.toString();
    }

    /**
     * ascii字符串转16进制字符串
     *
     * @param asciis
     * @return
     */
    public static String asciisToHex(String asciis) {
        char[] chars = asciis.toCharArray();
        StringBuilder hex = new StringBuilder();
        for (char ch : chars) {
            hex.append(Integer.toHexString((int) ch));
        }
        return hex.toString();
    }



版权声明:本文为qq_30038111原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。