I'm far from an expert on internals, but IIRC, the "internal representation" of a number in Perl is as a binary 64-bit IEEE-754 float. You've only been looking at 8 bits (B8) of the 64. Note that the positive and negative numbers below differ in one single bit in their binary FP representations.

c:\@Work\Perl\monks>perl -wMstrict -le "my @ra = (0.000008, -0.000008); ;; for my $fpn (@ra) { my $pfpn = pack 'F', $fpn; printf qq{%8s: length when F-packed: %d bytes \n}, $fpn, length $pf +pn; } ;; for my $fpn (@ra) { my $pfpn = pack 'F', $fpn; printf qq{%8s: hex '%s' \n}, $fpn, unpack 'H*', $pfpn; } ;; for my $fpn (@ra) { my $pfpn = pack 'F', $fpn; printf qq{%8s: bits '%s' \n}, $fpn, unpack 'B*', $pfpn; } " 8e-006: length when F-packed: 8 bytes -8e-006: length when F-packed: 8 bytes 8e-006: hex '8dedb5a0f7c6e03e' -8e-006: hex '8dedb5a0f7c6e0be' 8e-006: bits '100011011110110110110101101000001111011111000110111000 +0000111110' -8e-006: bits '100011011110110110110101101000001111011111000110111000 +0010111110'

Update: See Wikipedia article IEEE floating point. (Update: Oh, and also see What Every Computer Scientist Should Know About Floating-Point Arithmetic and What Every Computer Scientist Should Also Know About Floating-Point Arithmetic — how could I forget?)

Update 2: Changed code example to include hex unpacking.


In reply to Re: How to convert negative and positive floating points to binary and vice versa by AnomalousMonk
in thread How to convert negative and positive floating points to binary and vice versa by thanos1983

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.