位与&&位或

This commit is contained in:
flykhan 2023-06-19 15:14:11 +08:00
parent 1a98dde7d5
commit ce8fa14892
1 changed files with 26 additions and 0 deletions

26
day6/d6.cpp Normal file
View File

@ -0,0 +1,26 @@
#include <iostream>
using namespace std;
int main()
{
// 定义 Linux 的文件权限
int r = 4, w = 2, x = 1;
int n = 0;
// 为 n 值添加 r 和 w 权限
n = r | w; // 6: | 位或运算符
cout << "n = " << n << endl; // 6
// 为 n 值添加 x 权限
n |= x; // 7
cout << "n = " << n << endl; // 7
// 验证 n 是否包含 w 权限
if (n & w == w) // 7 & 2 == 2: & 位与运算符
{
cout << "n 包含 w 权限" << endl;
}
return 0;
}