Depends on the system: if you've got a 32-bit IV (perl -V:ivsize or perl -MConfig -le 'print $Config{ivsize}' will show 4 bytes for 32-bit, 8 bytes for 64-bit), then even that won't work, because it will overrun the 32-bit integer at 1<<32 - 1. And even with 64 bits, it will stop working above 64:

require v5.16; use Test::More qw(no_plan); for(51..66) {my $s = sprintf("%b", 1 << $_ -1); is length($s), $_, "1 << $_ -1"; } __END__ ok 1 - (1 << 51) -1 ok 2 - (1 << 52) -1 ok 3 - (1 << 53) -1 ok 4 - (1 << 54) -1 ok 5 - (1 << 55) -1 ok 6 - (1 << 56) -1 ok 7 - (1 << 57) -1 ok 8 - (1 << 58) -1 ok 9 - (1 << 59) -1 ok 10 - (1 << 60) -1 ok 11 - (1 << 61) -1 ok 12 - (1 << 62) -1 ok 13 - (1 << 63) -1 ok 14 - (1 << 64) -1 not ok 15 - (1 << 65) -1 # Failed test '(1 << 65) -1' # at - line 6. # got: '64' # expected: '65' not ok 16 - (1 << 66) -1 # Failed test '(1 << 66) -1' # at - line 6. # got: '64' # expected: '66' 1..16 # Looks like you failed 2 tests of 16.

So, philiprbrenan, "is this something to worry about?" depends on what you want to do. It's doing exactly what's expected for a double-float NV. And my example code does what's expected for a 64-bit integer. But as to whether that's behavior to worry about depends on what you're trying to do with your 2**$_n-1.


In reply to Re^2: Converting 2**54-1 to Binary by pryrt
in thread Converting 2**54-1 to Binary by philiprbrenan

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.