不能谷歌,百度了很久,没有直接的转换方法,参考
byte[]数组与十六进制字符串与字符串的互相转换
http://blog.163.com/[email protected]/blog/static/113561841201013525720/
通过
http://www.4jhm.com/hzcode/queryg.php验证,如下方法应该能实现。
public class Test {
public static void main(String[] args) {
String hzString = "人民比";
byte[] arrInput;
try
{
char[] chars = "0123456789ABCDEF".toCharArray();
arrInput = hzString.getBytes("GBK");
StringBuilder sOutput = new StringBuilder(arrInput.length);
int bit;
for (int i = 0; i < arrInput.length; i++) {
bit = (arrInput[i] & 0x0f0) >> 4;
sOutput.append(chars[bit]);
bit = arrInput[i] & 0x0f;
sOutput.append(chars[bit]);
}
System.out.println(sOutput.toString());
} catch (UnsupportedEncodingException e){
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}