php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #6368 Bitwise NOT does not work
Submitted: 2000-08-26 12:56 UTC Modified: 2002-01-28 20:13 UTC
From: jonny at 1409 dot org Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.1pl2 OS: Linux 2.2.16
Private report: No CVE-ID: None
 [2000-08-26 12:56 UTC] jonny at 1409 dot org
Maybe i'm just too stupid, but this one is strange:

The logical operator ~ (bitwise NOT) does not behave as expected. When
doing a "~1" (00000000000000000000000000000001), i get
2 (10000000000000000000000000000001) so it only seems to
invert the first bit?!

Furthermore when doing some simple mathematicaloperations, PHP behaves extremely annoing. Right-shifting (>>) a negative number will
always produce a negative result, i.e. the +/- bit gets not
shifted. Although you are right when you claim that this one is ok,
there are situations when you want the sign bit to get also shifted,
and there seems to be no simple way for doing that in PHP :-(

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-08-26 12:58 UTC] jonny at 1409 dot org
Sorry, there's an error in my Bug report.

When I do a "~1" i get -2, not 2.

Sorry again...

 [2000-08-26 13:40 UTC] stas@php.net
Why did you decide that -2 is 10000000000000000000000000000001? It isn't.
 [2000-08-26 13:41 UTC] stas@php.net
And signed shift operations is not a bug, moving to feature request.
 [2002-01-28 20:13 UTC] yohgaki@php.net
Is this feasible? 
I think it's not, unless we support unsinged int/long type......
And it will be more confusing than bitwise operation....

Won't change.

Please feel free to reopen if you are willing to discuss more about this.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 21:01:30 2025 UTC