枚举位移计算操作

如:

typedef NS_ENUM(NSInteger, Test)  

{                                              //     十进制        二进制

    TestA       = 1 << 0,              //         1          00001  

    TestB       = 1 << 1,             //          2          00010      

    TestC       = 1 << 2,            //           4          00100     

    TestD       = 1 << 3,           //            8          01000      

    TestE       = 1 << 4            //            16         10000      

}; 

// 判断是否包含某个值

Test tes = (TestA|TestB);  // 00011

if ((tes & TestA)) {           // 00011 & 00001 = 00001

    NSLog(@"有");  

} else  {  

    NSLog(@"没有");  

// 加上某个值的表达式为:

tes |=TestA;   // 00011 | 00001

 

// 减去某个值的表达式为:

tes ^=TestC;  // 00011 ^ 00001

posted @ 2017-05-09 14:48  浪人残风  阅读(292)  评论(0编辑  收藏  举报