Re: [PHP] Bitwise operators and check if an bit is NOT within the flag.

2006-07-07 Thread Richard Lynch
On Tue, July 4, 2006 7:35 am, Mathijs wrote:
 //Do if VALIDATE_CHECK1 is set BUT NOT when VALIDATE_CHECK3 is set.
 if ($flag2  self::VALIDATE_CHECK1  $flag2  ~self::VALIDATE_CHECK3)

Did you check operator precedence for  versus ?

Perhaps you just need parentheses...

I'm also not at all sure the ~self::VALIDATE_CHECK3 is doing what you
want...  Echo that out and see if it's the number you would expect...

-- 
Like Music?
http://l-i-e.com/artists.htm

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



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

2006-07-04 Thread Mathijs

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.

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



Re: [PHP] Bitwise operators and check if an bit is NOT within the flag.

2006-07-04 Thread Jochem Maas
Mathijs wrote:
 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) {

class Test {
const VALIDATE_CHECK1 = 1;
const VALIDATE_CHECK2 = 2;
const VALIDATE_CHECK3 = 4;
const VALIDATE_ALL= 7;
static function check($flag2)
{
if (($flag2  self::VALIDATE_CHECK1) 
!($flag2  self::VALIDATE_CHECK3)) print Only Validate 1;
}
}

echo First attempt: ;
Test::check( Test::VALIDATE_ALL );
echo \nSecond attempt: ;
Test::check( Test::VALIDATE_CHECK1 );
echo \n;
 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.
 

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