### quik question about the '|' sign

I know the that you can do someting like
 `` `` `` getSomething(ONE_THING | ANOTHER_THING);``

where you make use of the '|'.
But how do is recieve and use those multyple things?
It's called a bitwise inclusive OR operator. Read about it here

http://msdn.microsoft.com/en-us/library/edc0fscw.aspx
For example that to check that at least one number of two numbers is non-zero.

 ``1234567`` ``````int x = 0, y = 0; std::cout << "Enter two numbers: "; std::cin >> x >> y; if ( x | y ) std::cout << "At least one number is not equal to zero.\n"; else std::cout << "Both numbers are equal to zero.\n";``````
 ``1234567891011121314151617181920`` ``````enum MyThings { THING_ONE = 0x1, THING_TWO = 0x2, THING_THREE = 0x4, THING_FOUR = 0x8, THING_FIVE = 0x10, THING_SIX = 0x20, THING_SEVEN = 0x40, THING_EIGHT = 0x80 }; int things = THING_ONE|THING_FOUR; bool has_one = (things&THING_ONE) == THING_ONE; bool has_two = (things&THING_TWO) == THING_TWO; bool has_three = (things&THING_THREE) == THING_THREE; bool has_four = (things&THING_FOUR) == THING_FOUR; bool has_five = (things&THING_FIVE) == THING_FIVE; bool has_six = (things&THING_SIX) == THING_SIX; bool has_seven = (things&THING_SEVEN) == THING_SEVEN; bool has_eight = (things&THING_EIGHT) == THING_EIGHT;``````

You cannot use arbitrary number.
You must use numbers who are made of a single binary bit activated.

E.G. :
Hex -> Binary
0x1 == 00000001
0x2 == 00000010
0x4 == 00000100
0x8 == 00001000
0x10== 00010000
0x20== 00100000
0x40== 01000000
0x80== 10000000
ty so much guys
@vlad: Your example also works with ||.
I think DutchMofo meant how to use bitmasks/bitwise operators.
Topic archived. No new replies allowed.