Solved

max number

Posted on 2008-09-29
5
202 Views
Last Modified: 2008-09-29
hello there,
I have this code but I would like to know what will be the max number I can have.. as of now I have it set to 151
will it be possible to have it over millions or it will take up high loads on the server and memory?
$checkthisnumber = '50';
 
$i=1;
while ($i < 151) 
{
        
 if ($i == $checkthisnumber) 
        {
                echo $checkthisnumber . ' number found';
                break;
        }
$i++;
}

Open in new window

0
Comment
Question by:XK8ER
  • 4
5 Comments
 
LVL 7

Expert Comment

by:ahalya
ID: 22595757
Well, it depends on the type of "i"

if you are looking for smaller ranges then use byte or word

If the type of i is

byte: 0..255  (8 bit)
word: 0..65535 (16 bit)

You can have much larger ranges by using integer, longint, cardinal etc. See Delphi's help file for the ranges.

The loop takes longer to execute with a higher number, but there is no concern in terms of memory.  
0
 
LVL 7

Accepted Solution

by:
ahalya earned 500 total points
ID: 22595767
From Delphi Help:

Shortint      -128..127      signed 8-bit
Smallint      -32768..32767      signed 16-bit
Longint      -2147483648..2147483647      signed 32-bit
Int64      -2^63..2^63-1      signed 64-bit
Byte      0..255      unsigned 8-bit
Word      0..65535      unsigned 16-bit
Longword      0..4294967295      unsigned 32-bit
0
 
LVL 7

Expert Comment

by:ahalya
ID: 22595802
ouch, sorry. I thought I was in the Delphi forum.  For php, the maxsize is dependent on the platform. but in most cases it will be 32-bits.

Which is to say that you can go from -2147483648 to 2147483647. (in most cases)

0
 
LVL 7

Expert Comment

by:ahalya
ID: 22595811
Also, you can use PHP_INT_MAX to determine the maximum size of the integer.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 22597108
@XK8ER: You can count up to very high numbers, but I am curious... What is the intended purpose of the example you posted above?  It looks like it is just loops, adding one until it comes to (drum roll) a number you ALREADY KNOW!  Please tell us a little more about your objectives.

To answer your direct question, yes it will place a load on the processor, and no, it will not place a load on memory.

See the man page here for info on largest integers:
http://us3.php.net/manual/tr/reserved.constants.php
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question