Link to home
Start Free TrialLog in
Avatar of Jax Logan
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";

      }
ASKER CERTIFIED SOLUTION
Avatar of jeromee
jeromee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ozo
or
perl -lne 'BEGIN{$/=\4}print unpack"H*"' /tmp/bf
Avatar of Jax Logan
Jax Logan

ASKER

very awesome!!! Thanks!