Bug #3176: Using Bit manupulation ( Bitwise AND, OR, XOR, NOT) do not work as expected

From: Date: Tue, 11 Jan 2000 12:56:44 +0000
Subject: Bug #3176: Using Bit manupulation ( Bitwise AND, OR, XOR, NOT) do not work as expected
Groups: php.dev 
Request: Send a blank email to php-dev+get-14495@lists.php.net to get a copy of this message
From: markj@usn.nl Operating system: HPUX/10 PHP version: 3.0.13 PHP Bug Type: Misbehaving function Bug description: Using Bit manupulation ( Bitwise AND, OR, XOR, NOT) do not work as expected I encountered this with version 4.0b3, but I suspect it to be in other versions too... i'll check as soon as I can get 3 running somewhere... I'm currently using PHP4.0b3, and have encountered some inconsistencies when manipulating an integer number at the bit level. I use this integer 'settings' to store up to 30 user-configurable settings for my application. 0 being that all are turned off. When I toggle a specific bit (with my own function toggle_bit( &$bitfield, $bitnr ) (included below)) i get really strange results if I for example do this: $settings = 0; toggle_bit( $settings, 1 ) /* This should toggle bit with value 1, making $settings 1... */ echo $settings /* This will return garbage... */ This gives random results (probably because $settings is signed, the result always has a 1 as the first bit (when i do bindec), but isn't -1 (two's complement) When I first 'turn my value into a unsigned int' by or-ing it with 0: $settings = 0 $newset = ( $settings | 0 ) toggle_bit( $newset, 1 ) echo $newset /* This will return the expected value of 1... */

« previous php.dev (#14495) next »