Bitwise operators and check if an bit is NOT within the flag.

From: Date: Tue, 04 Jul 2006 12:35:40 +0000
Subject: Bitwise operators and check if an bit is NOT within the flag.
Groups: php.general 
Request: Send a blank email to php-general+get-239116@lists.php.net to get a copy of this message
Hello there. I am working with some bitwise Operators for validating some variables. Now i need to know if an certain bit is NOT set and an other bit IS set. Example. <?php const VALIDATE_CHECK1 = 1; const VALIDATE_CHECK2 = 2; const VALIDATE_CHECK3 = 4;
const VALIDATE_ALL    = 7;
//--Example 1 - This works nice. $flag1 = self::VALIDATE_CHECK1; //Do if VALIDATE_CHECK1 is set if ($flag1 & self::VALIDATE_CHECK1) {
    print 'Validate 1';
} //Do if VALIDATE_CHECK2 is set if ($flag1 & self::VALIDATE_CHECK2) {
    print 'Validate 2';
} //--Example 2 - I want to check if VALIDATE_CHECK3 is not set and then continue. $flag2 = self::VALIDATE_ALL; //Do if VALIDATE_CHECK1 is set BUT NOT when VALIDATE_CHECK3 is set. if ($flag2 & self::VALIDATE_CHECK1 && $flag2 & ~self::VALIDATE_CHECK3) {
    print 'Only Validate 1';
} //etc... ?> This last example i can't seem to get to work. I Want to only do that when for example VALIDATE_CHECK3 is not within the $flag2. How can i do this? Thx in advanced.

« previous php.general (#239116) next »