Java Convert via ByteBuffer hexStrToStr(String hexStr)

Here you can find the source of hexStrToStr(String hexStr)

Description

hex Str To Str

License

Apache License

Declaration

public static String hexStrToStr(String hexStr) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;

public class Main {

    public static String hexStrToStr(String hexStr) {
        String decStr = "";
        ByteBuffer bytes = ByteBuffer.allocate(hexStr.length() / 2);
        for (int i = 0; i < hexStr.length(); i += 2) {
            Byte b = (byte) (0xff & Integer.parseInt(hexStr.substring(i, i + 2), 16));
            bytes.put(b);//from www . j a  v  a2 s  . co m
        }
        bytes.position();
        try {
            decStr = new String(bytes.array(), "GBK");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return decStr;
    }
}

Related

  1. hexDump(byte... b)
  2. hexDump(byte[] buffer)
  3. hexStringToBytes(String hexString)
  4. hexToAscii(byte[] src)
  5. hexToBytes(String hexStr)
  6. hexToBytes(String hexString)
  7. intArrayFromBytes(byte[] bytes)