转自:https://blog.csdn.net/wodeni512517/article/details/71123469
1.介绍
十六进制:
typedef enum { ACTION_SHOWCARDS = 0x01, //1 ACTION_FOLLOW = 0x02, //2 ACTION_ADDANTE = 0x04, //4 ACTION_GIVEUP = 0x08, //8 ACTION_COMPARE = 0x10,//16 } ActionState;
这样一个枚举表示一个状态,可以通过或运算|表示多个状态,再通过与运算&可以提取状态,例子:
typedef enum { ACTION_SHOWCARDS = 0x01, ACTION_FOLLOW = 0x02, ACTION_ADDANTE = 0x04, ACTION_GIVEUP = 0x08, ACTION_COMPARE = 0x10, } ActionState; int main(){ int a = ACTION_SHOWCARDS | ACTION_FOLLOW | ACTION_ADDANTE; printf("%d\n", a); printf("%d\n", a & ACTION_GIVEUP); printf("%d\n", a & ACTION_FOLLOW); return 0; } //打印结果 7 0 2
也可以使用二进制,上述链接中有提到。//但看起来没有16进制公工整,这里就不写了。
标签:SHOWCARDS,GIVEUP,16,状态机,枚举,ADDANTE,ACTION,FOLLOW From: https://www.cnblogs.com/BlueBlueSea/p/17056786.html