Created
May 27, 2013 10:42
-
-
Save mkrasowski/5656423 to your computer and use it in GitHub Desktop.
Converts a text file containing hexadecimal representation of a binary file content into a binary file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use 5.014; | |
use autodie; | |
do { | |
say "Usage: hex2bin <input> <output>"; | |
exit(1); | |
} unless @ARGV == 2; | |
my ($fin, $fout) = @ARGV; | |
open( I, "<$fin" ); | |
my $line = <I>; | |
close(I); | |
$line =~ s/\s//g; | |
chomp $line; | |
my @chars = unpack( "(A2)*", $line); | |
chomp @chars; | |
open( O, ">$fout" ); | |
print O chr( hex($_) ) foreach @chars; | |
close(O); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment