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
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
Correct Answer: Option C
Explanation
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:
4in binary is100.6in binary is110.
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); } }
Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic