
Introduction to Operators and Expression in Java • 63
3.7.3 Bitwise XOR (^)
Bitwise XOR (^) takes at least two bits (may be more
than two). If the number of 1’s are odd then the result is 1,
else the result is 0 (Table 3.13).
For example, consider the following program:
First Bit Second Bit Result
000
011
101
110
Table 3.13 Truth table of bitwise XOR (^)
/*PROG 3.15 DEMO OF BITWISE XOR (∂)OPERATOR */
class JPS15
{
public static void main(String args[])
{
byte b1 = 125, b2 = 107;
byte b3 = (byte)(b1 ^ b2);
System.out.println(“\n\nBehaviour of Bitwise
XOR”);
System.out.println(“\nThe value of b3:=” + b3);
}
}
OUTPUT: ...