要检查是否设置了位值:
int value = VALUE_TO_CHECK | OTHER_VALUE_TO_CHECK;if ((value & VALUE_TO_CHECK) == VALUE_TO_CHECK){ // do something--it was set}if ((value & OTHER_VALUE_TO_CHECK) == OTHER_VALUE_TO_CHECK){ // also set (if it gets in here, then it was defined in // value, but it does not guarantee that it was set with // OR without other values. To guarantee it's only this // value just use == without bitwise logic)}重要的是要注意,除非将其表示为All或None(并且不要使用按位逻辑进行比较;请使用
value == 0),否则不应将其检查值为0,因为any
value & 0始终为0。



