public class Operators {
public static void main(String[] args) {
int a = 12;
System.out.println("Bitwise AND:"+(12&12));
System.out.println("Bitwise inclusive OR:"+(12|12));
System.out.println("Bitwise exclusive OR:"+(12^12));
}
}
OUTPUT:
Bitwise AND:12
Bitwise inclusive OR:12
Bitwise exclusive OR:0
I understand first two, but not the third.
The | (bitwise OR) in C or C++ takes two numbers as operands and does OR on every bit of two numbers. The result of OR is 1 if any of the two bits is 1. The ^ (bitwise XOR) in C or C++ takes two numbers as operands and does XOR on every bit of two numbers. The result of XOR is 1 if the two bits are different.
BITWISE INCLUSIVE OR (|) means normal or operation , BITWISEE ExCLUSIVE OR (^) means xor operation.
The | (bitwise inclusive OR) operator compares the values (in binary format) of each operand and yields a value whose bit pattern shows which bits in either of the operands has the value 1 . If both of the bits are 0 , the result of that bit is 0 ; otherwise, the result is 1 .
XOR is a bitwise operator, and it stands for "exclusive or." It performs logical operation. If input bits are the same, then the output will be false(0) else true(1).
XOR tells whether each bit is different.
1 XOR 1 = 0
1 XOR 0 = 1
0 XOR 1 = 1
0 XOR 0 = 0
In other words "either but not both"
0011 XOR 0101 = 0110
BITWISE INCLUSIVE OR (|) means normal or operation ,
BITWISEE ExCLUSIVE OR (^) means xor operation
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