Search code examples
javabitwise-operators

In the following fragment, is the & a bitwise or logical operator? why?


In the following fragment, is the & a bitwise or logical operator? why?

boolean a, b;
//      
if (a & b)...

Solution

  • 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 &&.