#include<bits/stdc++.h>
using namespace std;
int main() {
int n, i, j;
cin >> n >> i >> j;
if (i > j) swap(i, j);
cout << "n的第i位为" << ((n >> (i - 1)) & 1) << "\n";
cout << "n的后i位为" << (n & ((1 << i) - 1)) << "\n";
cout << "n的第j位为" << ((n >> (j - 1)) & 1) << "\n";
cout << "n的后j位为" << (n & ((1 << j) - 1)) << "\n";
cout << "n的第i位~第j位为" << ((n & (1 << (j - i + 1)) - 1)) >> (i - 1)) << "\n";
cout << "将n的第i位设为0后n为" << (n & (~(1 << (i - 1)))) << "\n";
cout << "将n的后i位设为0后n为" << (n & (~((1 << i) - 1))) << "\n";
cout << "将n的第i位设为1后n为" << (n | (1 << (i - 1))) << "\n";
cout << "将n的后i位设为1后n为" << (n | ((1 << i) - 1)) << "\n";
cout << "将n的第i位取反后n为" << (n ^ (1 << (i - 1))) << "\n";
cout << "将n的后i位取反后n为" << (n ^ ((1 << i) - 1)) << "\n";
cout << "将n的第j位设为0后n为" << (n & (~(1 << (j - 1)))) << "\n";
cout << "将n的后j位设为0后n为" << (n & (~((1 << j) - 1))) << "\n";
cout << "将n的第j位设为1后n为" << (n | (1 << (j - 1))) << "\n";
cout << "将n的后j位设为1后n为" << (n | ((1 << j) - 1)) << "\n";
cout << "将n的第j位取反后n为" << (n ^ (1 << (j - 1))) << "\n";
cout << "将n的后j位取反后n为" << (n ^ ((1 << j) - 1)) << "\n";
cout << "将n第i位~第j位设为0后n为" << (n & (~ (((1 << (j - i + 1)) - 1) << (i - 1)))) << "\n";
cout << "将n第i位~第j位设为1后n为" << (n | (((1 << (j - i + 1)) - 1) << (i - 1))) << "\n";
cout << "将n第i位~第j位取反后n为" << (n ^ ((1 << (j - i + 1)) - 1) << (i - 1));
return 0;
}剪贴板
剪贴板 ioi8sxtc
剪贴板信息
剪贴板信息
- 发布
- 收录
- 更新