Re: decimal -> Binary

John Douglas Porter <[email protected]> Wed, 16 Nov 2011 06:32:35 -0800 (PST)
Newsgroups gmane.comp.lang.perl.fun
Message-ID <[email protected]>
=0AWhat's the point?  Seems to me the only purpose of this code beyond the =
obvious=0A=0A    unpack("B*",pack("N", $arg))=0A=0Aline is to reformat the =
result into an odd, probably application-dependent format.=0A=0A=0A=0A--- O=
n Wed, 11/16/11, Sandro CAZZANIGA <[email protected]> wrote:=0A=0A=
> From: Sandro CAZZANIGA <[email protected]>=0A> Subject: decimal =
-> Binary=0A> To: [email protected]=0A> Date: Wednesday, November 16, 2011, 8:26=
 AM=0A> hi!=0A> =0A> Just a little JAPH for convert decimal to binary.... F=
eel=0A> free to comment=0A> it ;)=0A> -------------------------------------=
---------------------------=0A> #!/usr/bin/perl=0A> use strict;=0A> use war=
nings;=0A> eval {@ARGV} or die("No args") ;=0A> foreach my $arg(@ARGV) {=0A=
> =A0 =A0 my $convert =3D unpack("B*",pack("N", $arg));=0A> =A0 =A0 my @con=
vertsp =3D split("", $convert);=0A> =A0 =A0 my $count =3D 0;=0A> =A0 =A0 fo=
reach (@convertsp) {=0A> =A0 =A0 =A0 =A0 unless ($convertsp[$count] =3D=3D=
=0A> 1) {=0A> =A0 =A0 =A0 =A0 =A0 =A0=0A> $convertsp[$count] =3D "" ;=0A> =
=A0 =A0 =A0 =A0 =A0 =A0 $count++;=0A> =A0 =A0 =A0 =A0 }=0A> =A0 =A0 }=0A> =
=A0 =A0 print("$arg: @convertsp \n");=0A> }=0A> exit 0;=0A>