有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (2) 个答案

  1. # 1 楼答案

    有很多方法可以做到这一点。这里有一个:

    public static void main(String[] args) {
    
        String s = "de70d4de8c47385536c8e08348032c3b";
    
        Matcher m = Pattern.compile("..").matcher(s);
    
        List<Byte> bytes = new ArrayList<Byte>();
        while (m.find())
            bytes.add((byte) Integer.parseInt(m.group(), 16));
    
        System.out.println(bytes);
    }
    

    输出(-34==0xde):

    [-34, 112, -44, -34, -116, 71, 56, 85, 54, -56, -32, -125, 72, 3, 44, 59]
    
  2. # 2 楼答案

    未经证实:

    String md5 = "de70d4de8c47385536c8e08348032c3b";
    byte[] bArray = new byte[md5.length() / 2];
    for(int i = 0, k = 0; i < md5.lenth(); i += 2, k++) {
        bArray[k] = (byte) Integer.parseInt(md5[i] + md5[i+1], 16);
    }