Re: decimal -> Binary

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

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 comme=
nt
> it ;)

golfed down a bit, just for fun...

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

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

cheers,
0--gg-

--=20
_($_=3D" "x(1<<5)."?\n".q=B7/)Oo.  G=B0\        /
                               /\_=AF/(q    /
----------------------------  \__(m.=3D=3D=3D=3D=B7.(_("always off the cr=
owd"))."=B7
");sub _{s./.($e=3D"'Itrs `mnsgdq Gdbj O`qkdq")=3D~y/"-y/#-z/;$e.e && pri=
nt}
---1454121964-1975091555-1321453923=:15400--