Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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
Replies are listed 'Best First'.
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://430017]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2016-12-04 04:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (61 votes). Check out past polls.