|
-
Jul 1st, 2002, 09:10 PM
#1
Thread Starter
PowerPoster
Check against a value
I have a variable called, for example, "lstate". It can be a combination of ODS_DEFAULT, ODS_SELECTED, ODS_FOCUS, etc.
Now, I want to if it has ODS_SELECTED it in.
Here is how I am doing:
PHP Code:
if(lstate && ODS_SELECTED)
{
//ODS_SELECTED is in there
}
Is the above checking right?
-
Jul 1st, 2002, 09:57 PM
#2
I think if each of the possible values is a power of 2, this is the way...
PHP Code:
if ((lstate & ODS_SELECTED) == ODS_SELECTED)
{
//...ODS_SELECTED is in there...
}
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jul 1st, 2002, 10:14 PM
#3
Crptc is right. It will only work if the constant sets a bit on that no other constant sets. Also use the bit-wise & operator, not the && boolean operator
-
Jul 1st, 2002, 10:41 PM
#4
Originally posted by jim mcnamara
Crptc is right.
All right...1 out of 2500 ain't too shabby.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jul 1st, 2002, 11:08 PM
#5
Thread Starter
PowerPoster
Thanks, especially clearing about that bitwise operator...was messing up with them and inversing them.
Anyways, my code still isn't doing what I want it to but I guess it's some other problem...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|