root/paper-tape-project/trunk/perl-tools/punch-simulator
| Revision 1, 0.9 kB (checked in by sven, 4 years ago) |
|---|
| Line | |
|---|---|
| 1 | #!/usr/bin/perl -w |
| 2 | # kleines quick & dirty script zum Anzeigen von BYTES aus |
| 3 | # der Standardeingabe als Lochstreifen auf der Konsole |
| 4 | # (Standardausgabe) |
| 5 | # automatische Umwandlung von ASCII => Bytes o.ä. wird |
| 6 | # nicht vorgenommen - das Script verhält sich damit wie |
| 7 | # der Lochkartenpuncher |
| 8 | # |
| 9 | |
| 10 | while(<STDIN>) { # pro Zeile... |
| 11 | foreach($cpos=0; $cpos < length; $cpos++) { |
| 12 | $char = substr($_, $cpos, 1); |
| 13 | $char = ord($char); |
| 14 | #printf "Byte: %b\n", $char; |
| 15 | |
| 16 | print '|'; |
| 17 | $against = 0x01; # binär 0000 0001 |
| 18 | for($pos=0; $pos < 8; $pos++) { |
| 19 | print '.' if($pos == 3); # Lochführung an pos. 3 |
| 20 | $check = $char; |
| 21 | $check = ($check >> $pos); |
| 22 | if(($check & $against) == 0) { |
| 23 | print ' '; # bit nicht gesetzt |
| 24 | } else { |
| 25 | print '*'; # bit gesetzt |
| 26 | } |
| 27 | } |
| 28 | print "|\n"; |
| 29 | } # for |
| 30 | } # while |
| 31 | |
| 32 | exit 0; # fehlerlos enden. |
| 33 | |
| 34 |
Note: See TracBrowser
for help on using the browser.
Powered by
Expect where otherwise noted, content on this site is licensed under a