Skip to content
Advertisement

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

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

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

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement