“ compl”是一个内置关键字,至少从C ++ 98起就存在。它是~(Compliment)运算符的替代方法,它主要用于位操作。
compl关键字反转操作数的所有位。
语法:
compl operand
在这里,操作数是操作数。
示例
Input:
bitset<4> value("1100");
value = compl value;
Output:
value = 0011//C ++示例演示使用
//'compl'关键字
#include <iostream>
#include <bitset>
using namespace std;
int main(){
//位集
bitset<4> value("1011");
//操作前
cout << "value: " << value << endl;
value = compl value;
cout << "After operation (1)...\n";
cout << "value: " << value << endl;
value = compl value;
cout << "After operation (2)...\n";
cout << "value: " << value << endl;
return 0;
}输出:
value: 1011 After operation (1)... value: 0100 After operation (2)... value: 1011