|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11725 Bitwise operators seems buggy
Submitted: 2001-06-27 04:16 UTC Modified: 2001-06-28 13:10 UTC
From: Pascal dot Dufour at cdt dot eu dot int Assigned:
Status: Not a bug Package: Math related
PHP Version: 4.0.6 OS: Linux 2.2
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: Pascal dot Dufour at cdt dot eu dot int
New email:
PHP Version: OS:


 [2001-06-27 04:16 UTC] Pascal dot Dufour at cdt dot eu dot int
I have a problem with bitwise operator:
The following script:

printf("%08x (should be 05CDEA00)<BR>", (0x05CDEA00 & 0xFFFFFFFF));
printf("%08x (should be FFFFFFFF)<BR>", (0x05CDEA00 | 0xFFFFFFFF));


00000000 (should be 05CDEA00)
-7a321600 (should be FFFFFFFF)

It seems that the bitwise 'and' does not work at all, it always returns 0.
I do no understant the result of the bitwise 'or', and why it is displayed prefixed by a minus sign.

I have read the documentation and I think these are bugs...
I hope I have not misunderstood the doc.



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-27 12:25 UTC]
See bug #7755  for reason why this is not bug.

 [2001-06-27 15:14 UTC] Pascal dot Dufour at cdt dot eu dot int
I suppose you make ref to this:

>[2000-11-23 07:41:55]
>  Still not working, possibly won't for some time - since PHP
>   numbers are 32-bits signed, so they don't work well as
>   32-bit unsigned.
>[2000-12-12 05:56:20]
>   I suspend this bug since PHP has no good solution for it in
>  the foreseeable future. Please use GMP functions for this.
>[2001-05-13 05:33:17]
>  This is not a bug, so closing.

Is there any way to work with unsigned number ?
The goal is to do things like this (in a clean way):

$timestamp = time();
$buf .= chr(($timestamp & 0xff000000) >> 24);
$buf .= chr(($timestamp & 0xff0000) >> 16);
$buf .= chr(($timestamp & 0xff00) >> 8);
$buf .= chr($timestamp & 0xff);

then compute some hash...

Do you intend to provide such a 'feature' in a future release of PHP.
I understand you do not consider this to be a 'bug', since this is part
of the design of PHP. 
But, at least it is a missing 'feature'. When one work with hex numbers 
he does no want to handle the sign (in most cases) because the goal is 
to work at the bit level and not at the 'number' level.

 [2001-06-28 13:10 UTC]
Like in the #7755 was suggested, for now, use GMP functions.

 [2002-02-17 07:47 UTC] tcurdt at dff dot st
Guys, guys, guys! I've read #7755 but sorry - this definitly *IS* a bug!! Signed or unsigned - doesn't matter. It's what a user expects to work! If you ever programmed in Assembler you should know that signed or unsigned doesn't really matter (for this case) It's only a different interpretation on 32-bit number! Using GMP is not an real alternative.

As a matter of fact 45 & 0xFFFFFFFF is 45!!
As well as 45 & -1 is 45!!
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 13 08:01:29 2024 UTC