Re: decimal -> Binary

[email protected] (Georg Moritz) Wed, 16 Nov 2011 15:32:03 +0100 (CET)
Newsgroups perl.fwp
Message-ID <[email protected]>
---1454121964-1975091555-1321453923=:15400
Content-Type: TEXT/PLAIN; format=flowed; charset=ISO-8859-15
Content-Transfer-Encoding: 8BIT

Greetings Sandro & all,

From the keyboard of Sandro CAZZANIGA [16.11.11,14:26]:

> hi!
>
> Just a little JAPH for convert decimal to binary.... Feel free to comment
> it ;)

golfed down a bit, just for fun...

#!/usr/bin/perl -l
@ARGV or die "No args";
print"$_: ",($_=unpack"B*",pack"N",$_)=~s/0+//?$_:$_ for@ARGV;

> ----------------------------------------------------------------
> #!/usr/bin/perl
> use strict;
> use warnings;
> eval {@ARGV} or die("No args") ;
> foreach my $arg(@ARGV) {
>    my $convert = unpack("B*",pack("N", $arg));
>    my @convertsp = split("", $convert);
>    my $count = 0;
>    foreach (@convertsp) {
>        unless ($convertsp[$count] == 1) {
>            $convertsp[$count] = "" ;
>            $count++;
>        }
>    }
>    print("$arg: @convertsp \n");
> }
> exit 0;
>

cheers,
0--gg-

-- 
_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                               /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
---1454121964-1975091555-1321453923=:15400--