Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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 scrutinizing the Monastery: (3)
As of 2014-09-21 03:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (166 votes), past polls