Perl's pack function equivalent in Java

后端 未结 2 1100
清歌不尽
清歌不尽 2021-01-23 05:10

I have some Perl code that I need to transpose in Java. In this code I have to deal with Perl\'s pack. Is there an equivalent function in Java? The Perl code looks something lik

2条回答
  •  故里飘歌
    2021-01-23 06:14

    String hex = "4a616d6573";
    StringBuilder output = new StringBuilder();
    for (int i = 0; i < hex.length(); i+=2) {
        String str = hex.substring(i, i+2);
        output.append((char)Integer.parseInt(str, 16));
    }
    System.out.println(output);
    

提交回复
热议问题