OpenCores
URL https://opencores.org/ocsvn/workwithfiles/workwithfiles/trunk

Subversion Repositories workwithfiles

[/] [workwithfiles/] [trunk/] [from_bin2text.pl] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 asjohnas
#!/bin/perl
2
 
3
 
4
$file=@ARGV[0];
5
$len=@ARGV[1];
6
 
7
if ((length($file)==0) || (length($len)==0))
8
  {
9
   printf "\nInput parameters:\n from_bin2text.pl <binary_file_name> <number_of_bytes_in_outfile>\n";
10
   printf "Example: from_bin2text.pl bytesdata.bin 5000 >stimulus.txt\n\n";
11
   exit(0);
12
  }
13
 
14
open(F,"$file");
15
binmode F;
16
@lines=<F>;
17
close(F);
18
 
19
 
20
$txt='';
21
$bytenum=1;
22
foreach(@lines)
23
{
24
  $txt=$_;
25
  for ($z=0;$z<length($txt);$z++)
26
  {
27
   $a=ord(substr($txt,$z,1));
28
   printf "$a\n";
29
   $bytenum++;
30
   if ($bytenum>$len) {exit(0);}
31
  }
32
}
33
 
34
 
35
 
36
sub hex2dec
37
{
38
 return sprintf("%d",hex($_[0]))."";
39
}
40
 
41
sub hex2bin
42
{
43
 return sprintf("%.4b",hex($_[0]))."";
44
}
45
sub dec2hex
46
{
47
 return sprintf("%.2x",$_[0])."";
48
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.