Given the variable $foo
containing binary data, how do I get the hexadecimal representation of $foo
in Perl?
If $foo
is a string containing arbitrary data, use unpack:
my $hex = unpack('H*', $foo);
If it's just an integer, use sprintf:
my $hex = sprintf('%x', $foo); # Or %X if you want upper-case letters
$ perldoc -f hex
…
To present something as hex,
look into "printf", "sprintf", or "unpack".
==>
$hex = sprintf("%x", $foo);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With