【发布时间】:2018-04-20 15:12:25
【问题描述】:
我们都习惯了这种操作寄存器:
SomeRegister |= (1 << What_ever_bit_I_wanna_change ) // we do this for changing a specific bit to one without changing the others.
SomeRegister &= ~(1 << What_ever_bit_I_wanna_change ) // we do this for changing a specific bit to zero without changing the others.
我打算使用相同的范例,但使用枚举,如下所示:
typedef enum {
Acc_2g (Something to change only the desired bits in the related register that I don't know how to do),
Acc_4g (Something to change only the desired bits in the related register that I don't know how to do)
}Res;
知道如何在枚举中使用位运算符吗?
【问题讨论】:
-
您可以为枚举符号赋值,例如
enum {x=(1<<3), y=(1<<4), ...}如果这就是你要问的。 -
您知道可以将枚举值初始化为任何整数吗?就像例如
Acc_2g = 4?您可以使用任何编译时常量表达式进行初始化,例如Acc_2g = 1 << 2。 A good beginners book 应该告诉你的。