Java Programming - Operators and Assignments - Discussion

Discussion Forum : Operators and Assignments - Finding the output (Q.No. 9)
9.
What will be the output of the program?
class Bitwise 
{
    public static void main(String [] args) 
    {
        int x = 11 & 9;
        int y = x ^ 3;
        System.out.println( y | 12 );
    }
}
0
7
8
14
Answer: Option
Explanation:

The & operator produces a 1 bit when both bits are 1. The result of the & operation is 9. The ^ operator produces a 1 bit when exactly one bit is 1; the result of this operation is 10. The | operator produces a 1 bit when at least one bit is 1; the result of this operation is 14.

Discussion:
34 comments Page 4 of 4.

Sumit said:   1 decade ago
Please explain this clearly and complete. I can't understand what is happning.

Jaz said:   1 decade ago
Well anyone make more clear.

Vineeth said:   1 decade ago
helo jasmin..here is the explanation
write numbers in binary
0000
0001
0010
....
....
....
1111
so we want to find out 11&9.
ie 1001
1000
----
1000----->9
using this value we can find y in successive operations as explained.
i think its a good question..thank you

S. Jasmine said:   2 decades ago
I can't understand that how this answer came, can somebody explain me?


Post your comments here:

Your comments will be displayed after verification.