Perl的pack函数在Java中是等效的 [英] Perl's pack function equivalent in Java
问题描述
我有一些Perl代码需要用Java转置。在这段代码中,我必须处理Perl的 pack
。 Java中是否有等价的函数? Perl代码看起来像这样:
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 like this:
$somevar = pack "H*", $vartopack;
推荐答案
Perl的包
/ unpack
函数是一个功能非常全面的转换工具,它有自己的格式语法(这里使用 H *
,这使得它将一个任意长的十六进制字符串作为输入),其中没有在Java世界中直接相当。然而,要翻译...
Perl's pack
/ unpack
functions are a highly versatile conversion utility with its own format syntax (used in H*
here, which makes it take an arbitrarily long hex string as input) of which there is no direct equivalent in the Java world. However, to translate...
$somevar = pack "H*", $vartoconvert;
...对于Java,您可以使用:
...to Java, you can for example use:
byte[] somevar = javax.xml.bind.DatatypeConverter.parseHexBinary(vartoconvert);
有关更多信息,请阅读 DatatypeConverter
class reference 来自Javadocs。
For more information read the DatatypeConverter
class reference from Javadocs.
这篇关于Perl的pack函数在Java中是等效的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!