qfedu-basic-level/day6/case3.cpp

15 lines
382 B
C++
Raw Permalink Normal View History

2023-06-19 16:20:48 +08:00
// 案例3: data 为 1 字节, 将 data 的第 3, 4 位清0, 5, 6 置 1 其他位保持不变
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
char data = 0b10011011;
cout << "原值: " << bitset<8>(data) << endl;
data = (data & ~(0x1 << 3 | 0x1 << 4)) | (0x1 << 5 | 0x1 << 6);
cout << "结果: " << bitset<8>(data) << endl;
return 0;
}