|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-01-20 00:50 UTC] bpita at netcombbs dot com
Description:
------------
Hi,
I use this code in differents operating systems and plataforms (intel and amd) and return differents results.
It's a bug ? Any comments ?
Thanks, Bernardo.
Reproduce code:
---------------
echo ip2long('255.255.255.128');
echo ip2long('255.255.255.192');
echo ip2long('255.255.255.248');
Expected result:
----------------
32 bits systems returns:
-128
-64
-8
---------------------
64 bits systems returns:
4294967168
4294967232
4294967288
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 18:00:02 2025 UTC |
"but I use an internal function of php that returns differents values depends of my processor architecture ? It's correct ? " No, it is not correct. It is the _same_ value. But PHP has only signed integer. A signed integer can be used to store an unsigned integer. But when you display it, it thinks that is a negative number. Try: echo dechex(ip2long("255.255.255.128"));'Thanks, I understand. Searching I found this solution, and now I have the same value in both systems: $x = ip2long('255.255.255.248'); if ($x < 0) { $x+=pow(2,32); } It's correct ? Can I expect that work in the future no matter the value that I pass? P.S.: maybe you can put and aclaration in ip2long function about this, I found many questions for the same problem when searching "signed" and "unsigned" in php bugs. Thanks for your help, Bernardo.