Jax Logan
asked on
How to convert a binary file to Hex string? (Perl)
Experts,
how do I convert a binary file to a hex string in Perl?
not-so-working example:
open(BS_FILE, $bs_file_bin) or die "can't open $bs_file_bin: $!";
binmode(BS_FILE);
@lines = <BS_FILE>;
for $line ( @lines ) {
chomp $line;
my $int = unpack("N", pack("B32", substr("0" x 32 . $line, -32)));
my $hex = sprintf("%x", $int );
print STDOUT "$hex\n";
}
how do I convert a binary file to a hex string in Perl?
not-so-working example:
open(BS_FILE, $bs_file_bin) or die "can't open $bs_file_bin: $!";
binmode(BS_FILE);
@lines = <BS_FILE>;
for $line ( @lines ) {
chomp $line;
my $int = unpack("N", pack("B32", substr("0" x 32 . $line, -32)));
my $hex = sprintf("%x", $int );
print STDOUT "$hex\n";
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
very awesome!!! Thanks!
perl -lne 'BEGIN{$/=\4}print unpack"H*"' /tmp/bf