php.net |  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
Votes:6
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mccohy at kyberdigi dot cz
New email:
PHP Version: OS:

 

 [2004-09-29 10:17 UTC] mccohy at kyberdigi dot cz
Description:
------------
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:
---------------
$a=924303769;
$ax=-2147483649;
echo ($a & $ax)."\n"; 


Expected result:
----------------
924303769

Actual result:
--------------
0

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] hholzgra@php.net
-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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 14:01:31 2024 UTC