php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40178 Differents systems return differents values
Submitted: 2007-01-20 00:50 UTC Modified: 2007-01-20 13:04 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: bpita at netcombbs dot com Assigned:
Status: Not a bug Package: *Network Functions
PHP Version: 5.2.0 OS: Win32, Linux32 and Linux64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bpita at netcombbs dot com
New email:
PHP Version: OS:

 

 [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



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-20 02:15 UTC] pajoye@php.net
(bogus means "Not a bug" here)

This is the internal representation of signed integer using unsigned integer. 32bits use one bit for the sign, that explains the negative _displayed_ values, but the internal values are the same.

Big numbers should be processed using bcmath or pecl/big_int
 [2007-01-20 04:08 UTC] bpita at netcombbs dot com
Thanks, for your answer, I try to understand... but I use an internal function of php that returns differents values depends of my processor architecture ? It's correct ? Not should be the same and Php be in charge of this and return alway the same value independently of the 32b or 64b processor ?

Thanks, Bernardo.
 [2007-01-20 12:29 UTC] pajoye@php.net
"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"));'


 [2007-01-20 13:04 UTC] bpita at netcombbs dot com
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.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 17:01:28 2025 UTC