|
#!/usr/bin/perl -w
#- Bin2Hex.pl
($in, $out, $size) = @ARGV;
die "Missing input file name.\n" unless $in;
die "Missing output file name.\n" unless $out;
die "Missing file size(unit KB).\n" unless $size;
$byteCount = 0;
open(IN, "< $in");
binmode(IN);
open(OUT, "> $out");
#while (read(IN,$b,4)) {
#while () {
while ($byteCount < ($size*1024)) {
if (read(IN,$b,4)) {
$n = length($b);
$byteCount += $n;
$s = 2*$n;
print (OUT unpack("H$s", reverse split /(..)/, $b), "\n");
}
else {
$byteCount += 4;
print (OUT "00000000\n");
}
}
close(IN);
close(OUT);
print "Number of bytes converted = $byteCount\n";
exit;
#!/usr/local/bin/perl
$infile = "$ARGV[0]";
open(IN,"$infile") || die "$infile: $!\n";
@lines = <IN>;
close(IN);
for($i=1;$i<$#lines;$i++) {
&oneline($lines[$i]);
}
exit;
#---------------------------------------------------#
sub oneline {
my ($aline) = @_;
print $aline;
my @chars = split('',$aline);
for($j=1;$j<$#chars;$j++) {
if($chars[$j] == 0x0032) { print "$chars[$j]\n"; }
}
print $bline;
}
|
|