Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Binary decoder

by neniro (Priest)
on Feb 11, 2005 at 08:39 UTC ( #430017=snippet: print w/ replies, xml ) Need Help??

Description: Sometime ago, some insane guy posted a lot of binary into a thread on a german news-forum. First I thougt it could be a kind of simple riddle so I tried to convert it to ASCII to see what it is, but it was just binary-polution. That's the conversion script:
#!/usr/bin/perl

use strict;
use warnings;

while(<DATA>) {
  chomp;
  my @cur = split(//, $_);
  my $val = 0;
  for (0..7) { $val += pop(@cur) * 2**$_; }
  print $., "\t", $val, "\t", chr($val), "\n";
}

__DATA__
01101010
10010101
01010101
01011011
01001101
01101010
10011011
01010000
Comment on Binary decoder
Download Code
Re: Binary decoder
by merlyn (Sage) on Feb 11, 2005 at 09:08 UTC
      Hello merlyn,
      I'm not allergic, just ignorant. I'll promise to reread perlpacktut soon.

      thanks in advance,
      neniro

Re: Binary decoder
by Aristotle (Chancellor) on Feb 19, 2005 at 02:14 UTC

    Look ma, no unpack!

    #!/usr/bin/perl use strict; use warnings; while(<DATA>) { our $val = 0; # in-regex code is a closure... () = $_ =~ /1(?{$val+=1<<(pos()-1)})/g; print $., "\t", $val, "\t", chr($val), "\n"; } __DATA__ 01101010 10010101 01010101 01011011 01001101 01101010 10011011 01010000

    Makeshifts last the longest.

Back to Snippets Section

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2015-07-04 08:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (58 votes), past polls