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;
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's
pack
/unpack
functions are a highly versatile conversion utility with its own format syntax (used inH*
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......to Java, you can for example use:
For more information read the
DatatypeConverter
class reference from Javadocs.