Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Integer overflow in Perl and C

by rob_au (Abbot)
on Jan 24, 2004 at 12:21 UTC ( #323822=note: print w/replies, xml ) Need Help??

in reply to Integer overflow in Perl and C

3. Are there any other (neater) implementations of my script above

In terms of the original problem as presented, I believe that it an alternate approach employing the exponentiation operator/functions would be more efficient and side-step the format conversion problems.

In Perl:

perl -le 'print $_, ": 0 to ", 2**$_ - 1 for 0..32'
In C:
#include <stdio.h> #include <math.h> int main (void) { int i; for (i = 0; i <= 32; i++) printf("%d: 0 to %.f\n", i, pow(2, i) - 1); return(0); }
Both implementations are capable of outputting ranges of unsigned integer numbers for up to 64 bits (untested beyond).


perl -le "print unpack'N', pack'B32', '00000000000000000000001010110011'"

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://323822]
[karlgoethebier]: Discipulus: Workshops are for weenies ;-)
[Discipulus]: here 43C high umidity, tiger mosquitos, violence in the street.. everywhere is vietnam
[karlgoethebier]: OK, i'm socially unacceptable
[karlgoethebier]: Discipulus: Were the hell are you today?
[Discipulus]: ..or suitable for the presidence ;=)
[Discipulus]: at Caput Mundi
[marto]: choroba, have you moved to Vietnam or just there for a while?

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (11)
As of 2017-06-27 08:14 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (600 votes). Check out past polls.