Saturday, 7 September 2013

how can you check an individual binary digit in c++

how can you check an individual binary digit in c++

I apologize for being vague, but our teacher specifically told us to do so
if we ask questions
I have 9 flags I want to store as an integer.
ie, 0b111111111 would be all of them tripped.
Right now I have an if statement adding to the int if it's tripped. ie.
if (flag0=="tripped" && flag0=="hasn't been tripped before") flagInt += 1;
if (flag1=="tripped" && flag1=="hasn't been tripped before") flagInt += 2;
if (flag2=="tripped" && flag2=="hasn't been tripped before") flagInt += 4;
and so on,
I'm having difficulty writing the code to check if a flag has been tripped
or not. How could I do this?

No comments:

Post a Comment