Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Morse Code as binary

by serf (Chaplain)
on Jan 19, 2006 at 20:20 UTC ( #524337=CUFP: print w/ replies, xml ) Need Help??

After looking at ambrus' cool text to morse one-liner this morning:

Alphabetic->morse converter:

perl -wpe 's{[a-z ]}{"% etianmsurwdkgohvf%l%pjbxcyzq"=~/\l$&/;(unpack" + +B8",pack"C",@-)=~/0+1(.*)/;($x="$1")=~y/01/.-/;$x}gie'
I have been having a play with the idea of representing morse code in binary and came up with this:
#!/usr/bin/perl # # Morse Code as binary # # Given this table: # http://en.wikipedia.org/wiki/Morse_code # #Alternate_display_of_more_common_characters_for_the_international_c +ode # # Building an array padded with ~ (which is not used in Morse) # this turns the array index into a binary number representing # the Morse code: # the first 3 digits are the number of dits and dahs in the letter # the last 5 digits represent the morse symbol where 0 is . and 1 is _ # use strict; use warnings; my @chars = qw( E T I A N M S U R W D K G O H V F L P J B X C Y Z Q CH 5 4 ~ 3 ~ 2 ~ + ~ ~ 1 6 = / ~ ~ ~ ~ ~ 7 ~ ~ 8 ~ 9 0 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ? _ ~ ~ ~ ~ " ~ ~ . ~ ~ ~ ~ @ ~ ~ ~ ' ~ ~ - ~ ~ ~ ~ ~ ~ ~ ~ ; ! ~ () ~ ~ ~ ~ ~ % ~ ~ ~ ~ : ~ ~ ~ ~ ~ ~ ~ ); $chars[113] = ','; # Rather than having ',' in the qw() array. # These are the indices where the number of characters increase. my %steps; map( $steps{$_} = 1, qw(1 3 7 15 31) ); my ($step, $fig); for my $idx ( 1 .. $#chars ) { $chars[$idx] =~ s/^~$//g; if ( $steps{$idx} ) { $fig += 32; $step = $fig - $idx; } printf "%08b %s\n", $idx + $step, $chars[$idx-1]; }
Which could also be used as the basis for a Text->Morse / Morse->text convertor.

Comment on Morse Code as binary
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://524337]
Approved by bart
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-08-30 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls