From 2640064638eb52a528dde7d4623941f5e223b0ca Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Sun, 12 May 2013 00:52:59 +0200 Subject: [PATCH] morse.pl: morse code to binary char arrays generator --- projects/step-up/morse.pl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 projects/step-up/morse.pl diff --git a/projects/step-up/morse.pl b/projects/step-up/morse.pl new file mode 100755 index 0000000..085f313 --- /dev/null +++ b/projects/step-up/morse.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl -w + +my $code = shift @ARGV; + +$code =~ s/\./10000/g; +$code =~ s/-/1110000/g; +$code =~ s/\//000000/g; + +my $ones = ($code =~ y/1/1/); +my $len = length $code; + +if ($len % 8 != 0) { + $code .= '0' x (8 - ($len % 8)); +} + +$code =~ s/(.{8})/\t0b$1,\n/g; + +my $ratio = sprintf('%.1f', 100*$ones/$len); +print "\t/* $len bits, $ratio\% on */\n", $code; -- 2.39.3