example:
1010111110110001
0101011100010010
================
1010100010100001
|0 1
-|----
0|0 1
1|0 0
how to do this operation in c++ /c++11 ?
You can do a bitwise NOT and then AND them: a & ~b
Given:
a = 1010111110110001
b = 0101011100010010
Then negating b
gives:
~b = 1010100011101101
and doing a & ~b
:
a = 1010111110110001
~b = 1010100011101101
-------------------------
a & ~b = 1010100010100001
simple:
result = op1 & ~op2;
this inverts the second operand bitwise (1 becomes 0 and vice versa). After this you use a bitwise and. This is often called using a bitmask.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With