maximum integer length?
casevh at comcast.net
casevh at comcast.net
Sun Jun 18 14:42:56 CEST 2006
nate wrote:
> So I am just wondering how long an integer can be with 400 megabytes of
> memory.
>
> I guess this is a question of logic?
> each integer takes up a byte right? If I have 400 megabytes that would
> mean I could have a long integer with up to 419,430,400,000 integers?
>
Python longs are stored using 15 bits out of every 16 bits (2 bytes).
So every 2 bytes will contain approximately 4.5154 decimal digits.
Ignoring memory usage and overhead, the number of digits in the largest
possible long integer that can fit in 400 megabytes is
>>> import math
>>> 200 * 1024 * 1024 * 15 * math.log10(2)
946958486.2000643
Since memory space is required for temporary storage of intermediate
results, you won't actually be able to create a number that large if
you only have 400 megabytes.
casevh
More information about the Python-list
mailing list