SPUG: The bit pattern of a number (was sum-of-squares)

Ben Reser ben at reser.org
Sun Oct 5 12:51:20 CDT 2003


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.

-- 
Ben Reser <ben at reser.org>
http://ben.reser.org

"Conscience is the inner voice which warns us somebody may be looking."
- H.L. Mencken



More information about the spug-list mailing list