Integer size limitations
| From: | Richard Ellerbrock | Date: | Tue, 15 May 2001 14:47:37 +0000 |
| Subject: | Integer size limitations | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-52867@lists.php.net to get a copy of this message | ||
Please copy me on responses. TIA.
I am trying to do some IP address arithmetic using php, but am running into problems because the
biggest number that php can handle is 32 bits signed. No good for IP addresses.
Try the following:
echo 2473473024 & 127; // gives 0 - correct
echo 2473473025 & 127; // gives 0 - incorrect
echo 28288 & 127; // gives 0 - correct
echo 28289 & 127; // gives 1 - correct
What happens is that numbers that are bigger than 31 bits are automagically converted to double,
which does not allow binary operations (no error though, just wrong results!!!). Is there anyway to
make the number unsigned or a long int as in C? Else, how do I do binary arithmetic for IP
addresses?
This is using 4.04p1.
--
Richard Ellerbrock
richarde@eskom.co.za