in reply to Re: Handling binary
in thread Handling binary
I missed the part about having to generate these strings, here you go:
#!/usr/bin/perl # http://perlmonks.org/?node_id=1141773 use strict; use warnings; my $answer = handlingbinary( "139686DA20C1" ); print "$answer\n"; print tofivebit( 'ANONYMOUS MONK' ), "\n"; print tofivebit( 'COLINWRAY' ), "\n"; sub handlingbinary { return join '', ('A'..'Z')[ map { oct "0b$_" } (unpack 'B*', pack 'H*', shift()) =~ /.{5}/g ] } sub tofivebit { uc unpack 'H*', pack 'B*', shift() =~ tr/A-Z//cdr =~ s/(.)/ sprintf "%05b", ord($1) - ord('A' +) /ger; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Handling binary
by G109B (Initiate) on Sep 14, 2015 at 09:30 UTC |