public static String byteArrayToHexStr(byte[] byteArray) {
        if (byteArray == null){
            return null;
        }
        char[] hexArray = "0123456789ABCDEF".toCharArray();
        char[] hexChars = new char[byteArray.length * 2];
        for (int j = 0; j < byteArray.length; j++) {
            int v = byteArray[j] & 0xFF;
            hexChars[j * 2] = hexArray[v >>> 4];
            hexChars[j * 2 + 1] = hexArray[v & 0x0F];
        }
        return new String(hexChars);
    }

    public static byte[] hexStrToByteArray(String str)
    {
        if (str == null) {
            return null;
        }
        if (str.length() == 0) {
            return new byte[0];
        }
        byte[] byteArray = new byte[str.length() / 2];
        for (int i = 0; i < byteArray.length; i++){
            String subStr = str.substring(2 * i, 2 * i + 2);
            byteArray[i] = ((byte)Integer.parseInt(subStr, 16));
        }
        return byteArray;
    }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2021-11-13
  • 2021-08-19
  • 2021-07-17
  • 2022-12-23
  • 2021-11-30
猜你喜欢
  • 2021-08-11
  • 2022-12-23
  • 2021-05-05
  • 2021-06-21
  • 2021-09-05
  • 2021-09-03
  • 2022-12-23
相关资源
相似解决方案