十六进制字符串和byte数组的相互转化

来源:互联网 发布:java 1.7 32位官网 编辑:程序博客网 时间:2024/04/29 23:28
public static String getHexString(byte[] b) throws Exception {  String result = "";  for (int i=0; i < b.length; i++) {    result += Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring( 1 );  }  return result;} public static byte[] getByteArray(String hexString) {  return new BigInteger(hexString,16).toByteArray(); }

0 0