I looked at the 'D' format, and it would work on machines that have 64bit integer hardware, but I need to support some 32 bit only machines. But you got me thinking, and I used some basic math to get what I need (I hope?).

The following code seems to do what I need:

use strict; use warnings; my $num4g = 2 ** 32; my $grt4g = 500_000 + $num4g ; my $start = $num4g - 50; my $no = 0; while ( 1 ) { my $no1 = Pack( $start ); my $result = UnPack( "$no1" ); if ( $start != $result ) { die "not match"; } $start++; $no++; if ( $start >= $grt4g ) { print "Okay ( $no )\n"; exit; } } sub Pack { my $input = shift; my $lower = $input % $num4g; my $upper = int ( $input / $num4g ); return ( pack("N N", $upper, $lower ) ); } sub UnPack { my $input = shift; my ( $upper, $lower ) = unpack("N N", $input); return ( ( $upper * $num4g ) + $lower ); } 1;
I profiled the code and 'pack/unpack' sequence is about 2us/call. The 'Pack' is about 16us per call and the 'UnPack' is about 14us per call. Expensive, but I would then get network neutral code to 562TB, and that would be good.

Do you see anything wrong with the code?

Thank you

"Well done is better than well said." - Benjamin Franklin


In reply to Re^6: Will Perl Scripts written on 64 Bit Windows run fine on 32 bit as well? by flexvault
in thread Will Perl Scripts written on 64 Bit Windows run fine on 32 bit as well? 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.