qfedu-basic-level/day6/case2.cpp

16 lines
405 B
C++
Raw Permalink Normal View History

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