基本状态标识
short s1 = 1 << 0;//1
short s2 = 1 << 1;//2
short s4 = 1 << 2;//4
short s8 = 1 << 3;//8
short s16 = 1 << 4;//16
short s32 = 1 << 5;//32
short s64 = 1 << 6;//64
short s128 = 1 << 7;//128
short s256 = 1 << 8;//256
通过<< 获取二进制,后面注释为相对应10进制的值。
组合状态
int status = 0;
status |= s1; //1
status |= s2; //3
status |= s4; //7
status |= s8; //15
status |= s16; //31
status |= s32; //63
status |= s64; //127
status |= s128;//255
status |= s256;//511
通过或(|)运算符组合状态,注释为组合后的值。
判断状态
//组合状态
int status = 0;
status |= s1; //1
// status |= s2;
status |= s4; //5
status |= s8; //13
//判断状态
int rStatus=13;
rStatus & s1//1
rStatus & s2//0
rStatus & s4//4
rStatus & s8//8
通过与(&)运算符判断状态,不存在状态会返回0
判断返回值是否大于0就可以了
不要用 不要用 不要用 &=
用 int 还是 short 不影响程序结果。