The "q" format for pack()/unpack() is only supported if your copy of perl was compiled with quadword support (only available on some platforms).

But just about any version of Perl supports 53-bit integers which is often plenty, even when dealing with 64-bit data.

#!/usr/bin/perl -wl use strict; my $little; BEGIN { $little= unpack "C", pack "S", 1; } sub quad { my( $str )= @_; my $big; if( ! eval { $big= unpack( "Q", $str ); 1; } ) { my( $lo, $hi )= unpack "LL", $str; ( $hi, $lo )= ( $lo, $hi ) if ! $little; $big= $lo + $hi*( 1 + ~0 ); if( $big+1 == $big ) { warn "Forced to approximate!\n"; } } return $big; } my @quads= ( "\xff\xff\xff\xff\xff\xff\xff\xff", "\x00\x3f\xff\xff\xff\xff\xff\xff", "\x00\x1f\xff\xff\xff\xff\xff\xff" ); if( $little ) { for( @quads ) { $_= reverse $_; } } for( @quads ) { print quad( $_ ); } __END__ This prints: Forced to approximate! 1.84467440737096e+019 Forced to approximate! 1.8014398509482e+016 9.00719925474099e+015

Note that assumes an unsigned 64-bit integer.

        - tye (but my friends call me "Tye")

In reply to (tye)Re: 64 bit Integer anyone? by tye
in thread 64 bit Integer anyone? by dedwards25

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.