In the following fragment, is the & a bitwise or logical operator? why?
JavaScript
x
boolean a, b;
//
if (a & b)
Advertisement
Answer
If you regard booleans as single-bit numbers, then &
on booleans is consistent with a bitwise operation.
Java regards true and false as logical values, not numbers, so I would say that &
on booleans is a logical operator, not a bitwise operator. But people often refer to it as “bitwise &”, to distinguish it from &&
.