qfedu-basic-level/day6/case1.cpp

15 lines
401 B
C++

// 案例1: data 为 1 字节 将 data 的第 3, 4 位清 0 其他位保持不变
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
char n = 0b01011011; // 0x5b = 0101 1011
cout << "原值: " << bitset<8>(n) << endl;
// 1000 | 10000 = 0001 1000 ; ~00011000 = 11100111
n &= ~(0x1 << 3 | 0x1 << 4);
cout << "结果: " << bitset<8>(n) << endl;
return 0;
}