Examveda
Examveda

What is the result of the expression 5 | 3 in Java?

A. 7

B. 8

C. 1

D. 3

Answer: Option A

Solution(By Examveda Team)

Question: What is the result of the expression 5 | 3 in Java?

This question is about the bitwise OR operator (|) in Java. The bitwise OR operator compares the corresponding bits of two numbers. If either bit is 1, the resulting bit is 1; otherwise, it's 0.

Let's break it down:

First, we need to convert the decimal numbers 5 and 3 into their binary representations:

5 in decimal is 101 in binary
3 in decimal is 011 in binary

Now, let's perform the bitwise OR operation:

101 (5)
| 011 (3)
-------
111

The result in binary is 111. Converting 111 from binary back to decimal gives us 7.

Therefore, the expression 5 | 3 evaluates to 7.

Correct Answer: A

This Question Belongs to Java Program >> Operators

Join The Discussion

Comments ( 1 )

  1. Subrat Ojha
    Subrat Ojha :
    4 months ago

    0101 (binary for 5)
    | 0011 (binary for 3)
    ------
    0111 (binary result)
    A | B = Result
    0 | 0 = 0
    0 | 1 = 1
    1 | 0 = 1
    1 | 1 = 1
    - subrat

Related Questions on Operators