bool bit_get(int n, int bit) {
return (n & (1 << bit)) != 0;
}
int bit_set(int n, int bit, bool value) {
if (value) {
n |= 1 << bit;
} else {
n &= ~(1 << bit);
}
return n;
}
int bit_not(int n, int bit) {
return bit_set(n, bit, !bit_get(n, bit));
}
三个函数,功能分别是,获得某位的值,设置某位的值,和对某位取反
![](https://img-home.csdnimg.cn/images/20240711042549.png)