Front page | perl.fwp |
Postings from November 2011
Re: decimal -> Binary
Thread Previous
|
Thread Next
From:
Ronald J Kimball
Date:
November 16, 2011 06:57
Subject:
Re: decimal -> Binary
Message ID:
20111116145734.GA60671@penkwe.pair.com
On Wed, Nov 16, 2011 at 03:32:03PM +0100, Georg Moritz wrote:
> 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;
That should be s/0*//, otherwise you'll get the wrong result for numbers
above 2147483647.
Ronald
P.S. Golfed further:
#!/usr/bin/perl -l
print"$_: ",(unpack"B*",pack N,$_)=~/(1.*)/for@ARGV?@ARGV:die"No args"
Thread Previous
|
Thread Next