15 lines
382 B
C++
15 lines
382 B
C++
// 案例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;
|
|
} |