I just want to create a bit flag from a series of boolean variables so I can store one variable in a MySQL database instead of several booleans. For example, I have three boolean flags (A, B, C) and want to create a single bit flag based on the values of the boolean flags. I think this would work but I'm guessing there's a better (or more legible) way to do this:
int myBitFlag = A ? 1:0;
myBitFlag += B ? 2:0;
myBitFlag += C ? 4:0;
I'm not sure why I can't find anything about this and maybe it's because I'm doing it wrong or not using the correct terminology..
And to select all of the entries with B=true, would I use this?
SELECT * FROM table WHERE myBitFlag & 2 = 1