-1

in java are Logical Xor and Bitwise Xor share same ^

I tried to looked at my java book and seems so. So strange?

BufBills
  • 8,005
  • 12
  • 48
  • 90
  • possible duplicate of [Effect of a Bitwise Operator on a Boolean in Java](http://stackoverflow.com/questions/1724205/effect-of-a-bitwise-operator-on-a-boolean-in-java) – Joe Mar 01 '15 at 06:06

1 Answers1

2

It's both, depending on the operands.

JLS 15.22.1:

When both operands of an operator &, ^, or | are of a type that is convertible (§5.1.8) to a primitive integral type ...

or in other words, two integral operands result in a bitwise XOR.

    0  1

0   0  1
1   1  0

or JLS 15.22.2:

When both operands of a &, ^, or | operator are of type boolean or Boolean, then the type of the bitwise operator expression is boolean.

        false   true

false   false    true
 true    true   false

It isn't at all strange for operators to perform different functions depending upon operands - consider addition versus string concatenation. 2 + 2 and "Hello " + "world!" are clearly two different kinds of operations.

jdphenix
  • 15,022
  • 3
  • 41
  • 74