Cheers, that hit the spot.
It's one of these tricks you don't find lying around in front of you and usually I'm wondering what the hell people are doing with bitwise stuff (even though my genetic algorithm library does it's magic bitwise).
Here's a working demo in P5 for anyone else who wants to learn:
Code:
int RED = 1;
int GREEN = 2;
int BLUE = 4;
void setup(){
getFlag(GREEN|BLUE);
}
void getFlag(int flags){
if((flags&RED) > 0){
fill(255,0,0);
rect(0,0,30,30);
}
if((flags&GREEN) > 0){
fill(0,255,0);
rect(30,0,30,30);
}
if((flags&BLUE) > 0){
fill(0,0,255);
rect(60,0,30,30);
}
}
Note the code throws an exception if you take the bitwise shizzle out of parentheses.
And in other languages you don't need to test against zero.
Actionscript:
Code:
var RED = 1;
var GREEN = 2;
var BLUE = 4;
getFlag(GREEN|BLUE);
function getFlag(flags){
if(flags&RED){
trace("RED");
}
if(flags&GREEN){
trace("GREEN");
}
if(flags&BLUE){
trace("BLUE");
}
}