in reply to Re: One-liner ascii/bin
in thread One-liner ascii/bin
#!/usr/bin/perl -wT use strict; my $bin = ascii2bin('Rolf'); my $ascii = bin2ascii($bin); print "bin => $bin\n"; print "ascii => $ascii\n"; sub ascii2bin { my $ascii = shift; my $bin = join '', map {sprintf "%08b", ord($_)} split //, $ascii; return $bin; } sub bin2ascii { my $bin = shift; my $ascii = join '', map {chr(oct"0b$_")} $bin =~ /(\d{8})/g; return $ascii; } =OUTPUT bin => 01010010011011110110110001100110 ascii => Rolf
Or, as one-liners.....
perl -le 'print join"",map{sprintf"%08b",ord($_)}split//,pop' Rolf perl -le 'print join"",map{chr(oct"0b$_")}pop=~/(\d{8})/g' 01010010011 +011110110110001100110
-Blake
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: One-liner ascii/bin
by I0 (Priest) on Nov 13, 2001 at 11:25 UTC | |
by blakem (Monsignor) on Nov 13, 2001 at 11:48 UTC | |
by Rolf (Novice) on Nov 22, 2001 at 17:30 UTC | |
by mkmcconn (Chaplain) on Nov 24, 2001 at 01:19 UTC | |
by Rolf (Novice) on Nov 26, 2001 at 17:02 UTC | |
|
Re: Re: Re: One-liner ascii/bin
by Rolf (Novice) on Nov 12, 2001 at 17:59 UTC | |
by blakem (Monsignor) on Nov 12, 2001 at 18:10 UTC | |
by Rolf (Novice) on Nov 12, 2001 at 19:32 UTC |