|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30271 Bitwise operator returns unwanted values
Submitted: 2004-09-29 10:17 UTC Modified: 2004-10-23 20:51 UTC
Avg. Score:4.8 ± 0.4
Reproduced:6 of 6 (100.0%)
Same Version:6 (100.0%)
Same OS:5 (83.3%)
From: mccohy at kyberdigi dot cz Assigned:
Status: Wont fix Package: Math related
PHP Version: 5.0.2 OS: Linux
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.
Block user comment
Status: Assign to:
Bug Type:
From: mccohy at kyberdigi dot cz
New email:
PHP Version: OS:


 [2004-09-29 10:17 UTC] mccohy at kyberdigi dot cz
The bitwise operator "and" returns an unwanted value. Here is a simple example:

Let's store value 924303769 in variable $a and value -2147483649 in variable $ax. Now, let's count the 'bitwise and' of these two variables ($a & $ax).

PHP 5.0.2 returns zero. PHP 4.3.9 returns 924303769. I am not sure what happens in 5.0.0 or 5.0.1, sorry.

Reproduce code:
echo ($a & $ax)."\n"; 

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-18 00:18 UTC] almekind at xs4all dot nl
In php 5.0.1 it was still OK. Came with 5.0.2
 [2004-10-23 20:51 UTC]
-2147483649 is to big for a PHP int so it is actually treated as a float,
and the behavior of & on floats is undefined
 [2004-10-25 09:30 UTC] one_half at seznam dot cz
And what about to retype it to 64-bit integer ? :)) Or is that difficult ?? :))
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Mar 08 16:01:23 2021 UTC