php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28691 Bitwise AND operator does not work on high values
Submitted: 2004-06-08 07:02 UTC Modified: 2004-06-09 09:37 UTC
From: dneilsen at davislangdon dot com dot au Assigned:
Status: Not a bug Package: Math related
PHP Version: 4.3.7 OS: RedHat Linux 8 & 9
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dneilsen at davislangdon dot com dot au
New email:
PHP Version: OS:

 

 [2004-06-08 07:02 UTC] dneilsen at davislangdon dot com dot au
Description:
------------
I have tested this on two separate systems running Redhat 8 and redhat 9 respectively.  The Redhat 9 system is running php version 4.3.4 and the redhat 8 is running 4.3.7.

php.ini has not been altered and, in the case of the redhat 8 box (php 4.3.7), it was compiled with the following:
./configure --with-mysql --with-apxs=/www/bin/apxs 

It seems that the bitwise AND operator will not work for values over pow(2,30).  In the case of power 31 it returns a negative value and in the case of power 32 and above it returns 0.

Thank you for your time :)

Regards
Daniel Neilsen


Reproduce code:
---------------
<?
for($i=28; $i<34; $i++)
{
	$vala = pow(2,$i);
	$valb = pow(2,$i);
	$result = $vala & $valb;
	echo "$i - $vala & $valb = $result<br>";
}

Expected result:
----------------
28 - 268435456 & 268435456 = 268435456
29 - 536870912 & 536870912 = 536870912
30 - 1073741824 & 1073741824 = 1073741824
31 - 2147483648 & 2147483648 = 2147483648
32 - 4294967296 & 4294967296 = 4294967296 
33 - 8589934592 & 8589934592 = 8589934592 


Actual result:
--------------
28 - 268435456 & 268435456 = 268435456
29 - 536870912 & 536870912 = 536870912
30 - 1073741824 & 1073741824 = 1073741824
31 - 2147483648 & 2147483648 = -2147483648
32 - 4294967296 & 4294967296 = 0
33 - 8589934592 & 8589934592 = 0


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-08 10:02 UTC] derick@php.net
Not a bug, PHP doesn't support integers > 2^31 - 1 (we have a 32 bit signed integer only, larger numbers get converted to a float).
 [2004-06-09 00:07 UTC] dneilsen at davislangdon dot com dot au
Thanks for the comment Derick, but why wouldnt bitwise operators work on float numbers?
 [2004-06-09 09:37 UTC] derick@php.net
Because it doesn't make much sense, as they are encoded in way that bitwise ops don't really work. (But that discussion doesn't belong in this bugsystem).
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Oct 29 20:01:25 2020 UTC