NOT ( ~ ): Bitwise NOT is an unary operator that flips the bits of the number
i.e., if the ith
bit is 0, it will change it to 1 and vice versa.
Bitwise NOT
is nothing but simply the one’s complement of a number.
Lets take an
example : -
N = 5 =
(101)2
~N = ~5 = ~(101)2 = (010)2
= 2
code :
while(t--) { cin>>a>>b; n = a&b;
cout<<"and:"<<n<<endl; n = a|b; cout<<"or
:"<<n<<endl; n = a^b;
cout<<"xor:"<<n<<endl; a = ~a; // 1's compliment b = ~b+1; // 2's compliment cout<<"not:"<<a<<'
'<<b<<endl; } |
Comments
Post a Comment