here are the details:

i have four different machines (all linux, all i686). two of them are running perl 5.6.0, the other two 5.005.

i run the following test on all machines:

perl -e 'print("0x30"+0,"\n")'

here are the results:

first machine (5.6.0): 1.5
second machine (5.6.0): 48
third machine (5.005): 48
fourth machine (5.005): 1.5

the second and third machine always evaluate the expression to whatever the decimal value of the hex number in the string is. the first and fourh evaluate to a fractional number.

here is a test script i ran on one of the 'fractional' machines:

#!/usr/bin/perl for ($i=1; $i<64; $i++) { print(sprintf("%02X: ",$i),("0x".sprintf("%X",$i))+0,"\n"); }

here is the output:

01: 1 02: 1 03: 1.5 04: 1 05: 1.25 06: 1.5 07: 1.75 08: 1 09: 1.125 0A: 1.25 0B: 1.375 0C: 1.5 0D: 1.625 0E: 1.75 0F: 1.875 10: 1 11: 1.0625 12: 1.125 13: 1.1875 14: 1.25 15: 1.3125 16: 1.375 17: 1.4375 18: 1.5 19: 1.5625 1A: 1.625 1B: 1.6875 1C: 1.75 1D: 1.8125 1E: 1.875 1F: 1.9375 20: 1 21: 1.03125 22: 1.0625 23: 1.09375 24: 1.125 25: 1.15625 26: 1.1875 27: 1.21875 28: 1.25 29: 1.28125 2A: 1.3125 2B: 1.34375 2C: 1.375 2D: 1.40625 2E: 1.4375 2F: 1.46875 30: 1.5 31: 1.53125 32: 1.5625 33: 1.59375 34: 1.625 35: 1.65625 36: 1.6875 37: 1.71875 38: 1.75 39: 1.78125 3A: 1.8125 3B: 1.84375 3C: 1.875 3D: 1.90625 3E: 1.9375 3F: 1.96875

now what i need is an explanation :)


In reply to Re: Why are hex numbers inside strings extrapolating to numbers (incorrectly)? by lanzz
in thread Why are hex numbers inside strings extrapolating to numbers (incorrectly)? by Anonymous Monk

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.