SPUG: The bit pattern of a number (was sum-of-squares)
Mathew D. Watson
matw at eclipse-optics.com
Mon Oct 6 08:20:04 CDT 2003
Thanks folks! This looks perfect.
--Mat
> -----Original Message-----
> From: spug-list-bounces at mail.pm.org
> [mailto:spug-list-bounces at mail.pm.org]On Behalf Of John W. Krahn
> Sent: Sunday, October 05, 2003 2:38 PM
> To: SPUG List
> Subject: Re: SPUG: The bit pattern of a number (was sum-of-squares)
>
>
> On Sunday 05 October 2003 10:51, Ben Reser wrote:
> > On Sun, Oct 05, 2003 at 09:57:34AM -0700, John W. Krahn wrote:
> > > $ perl -le'print scalar reverse unpack "b*", pack "d", 1'
> > > 0011111111110000000000000000000000000000000000000000000000000000
> > > $ perl -le'print scalar reverse unpack "b*", pack "d", -1'
> > > 1011111111110000000000000000000000000000000000000000000000000000
> > > $ perl -le'print scalar reverse unpack "b*", pack "d", 1e25'
> > > 0100010100100000100010110010101000101100001010000000001010010001
> > > $ perl -le'print scalar reverse unpack "b*", pack "d", 1e-25'
> > > 0011101010111110111100101101000011110101110110100111110111011001
> >
> > pack/unpack doesen't return the internal representation, but rather
> > the representation that you asked for via your format. I.E. This
> > output may not match the output that perl actually was storing the
> > data in. Which is what I think he was looking for.
>
> It does if you use the correct formats:
>
> $ perl -le'print unpack "B*", pack "S", 0b0001001000110100'
> 0011010000010010
>
> That might be clearer using hexadecimal:
>
> $ perl -le'print unpack "H*", pack "S", 0x1234'
> 3412
>
> Which shows the little-endian representation on my Intel compatable
> machine.
>
>
> John
> --
> use Perl;
> program
> fulfillment
>
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
> POST TO: spug-list at mail.pm.org http://spugwiki.perlocity.org
> ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list
> MEETINGS: 3rd Tuesdays, U-District, Seattle WA
> WEB PAGE: http://www.seattleperl.org
>
>
More information about the spug-list
mailing list