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;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Perl’s
pack/unpackfunctions 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
DatatypeConverterclass reference from Javadocs.