]> www.fi.muni.cz Git - tinyboard.git/blob - projects/step-up/morse.pl
morse.pl: morse code to binary char arrays generator
[tinyboard.git] / projects / step-up / morse.pl
1 #!/usr/bin/perl -w
2
3 my $code = shift @ARGV;
4
5 $code =~ s/\./10000/g;
6 $code =~ s/-/1110000/g;
7 $code =~ s/\//000000/g;
8
9 my $ones = ($code =~ y/1/1/);
10 my $len = length $code;
11
12 if ($len % 8 != 0) {
13         $code .= '0' x (8 - ($len % 8));
14 }
15
16 $code =~ s/(.{8})/\t0b$1,\n/g;
17
18 my $ratio = sprintf('%.1f', 100*$ones/$len);
19 print "\t/* $len bits, $ratio\% on */\n", $code;