MCQ Single Best Answer Easy

QWhat is the result of the expression 4 & 6 using the bitwise AND operator in Java?

ID: #20162 Bitwise Operators 94 views
Question Info
#20162Q ID
EasyDifficulty
Bitwise OperatorsTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A 0
  • B 2
  • C 4
  • D 6
Correct Answer: Option C

Explanation

AND gate
Figure:

The bitwise AND operator (&) in Java performs a bitwise AND operation between the binary representations of two integers. In this case, 4 & 6 is equivalent to 0100 & 0110, resulting in 0010, which is 2 in decimal.

The result of the expression 4 & 6 using the bitwise AND operator in Java is 4.

Here's the explanation:

The bitwise AND operator (&) performs a bitwise AND operation between corresponding bits of two integers. In binary representation:

  • 4 in binary is 100.
  • 6 in binary is 110.

Performing bitwise AND operation on each pair of corresponding bits:


  100   (4 in binary)
& 110   (6 in binary)
-----
  100   (Result in binary)

Converting the binary result 100 back to decimal gives 4, so 4 & 6 evaluates to 4.


public class BitwiseANDExample {
    public static void main(String[] args) {
        // Perform bitwise AND operation
        int result = 4 & 6;

        // Display the result
        System.out.println("Result of 4 & 6: " + result);
    }
}

No Previous Next Question

Share This Question

Challenge a friend or share with your study group.