Bitwise NOT operator?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey everyone,

  I'm really not sure what's going on here:  basically, the bitwise
NOT operator seems to simply not work.  Here's an example of what I
see.

============Script============

$ cat bintest2.php

<?php

$bin = 2;
$notbin = ~$bin;

echo "Bin: " . decbin($bin) . "  !bin:  " . decbin($notbin) . "\n";
echo "Bin: $bin  !bin:  $notbin\n";


?>
=============================


============Output============

$ php bintest2.php
Bin: 10  !bin:  11111111111111111111111111111101
Bin: 2  !bin:  -3

=============================


Obviously that's not the expected response.  I expect to get something
more like this:

Bin: 10  !bin:  01
Bin: 2  !bin:  1


Can anyone shed some light on this for me?  The server is running an
old version of OpenSUSE, and php --version returns:

PHP 5.2.5 with Suhosin-Patch 0.9.6.2 (cli) (built: Dec 12 2007 03:51:56)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies


I get the same response on an Ubuntu 8.04 LTS server with PHP
5.2.4-2ubuntu5.10 with Suhosin-Patch 0.9.6.2.

Thanks in advance,

  Alex McKenzie
  amckenzie4@xxxxxxxxx

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux