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 );
}
}
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 2 of 4.
JaiShriRam said:
1 decade ago
Mansi Jain: ^ is EX-OR function,
which means if toggle answre is 1 else 0
eg: 9^3 ==
1001
0011
------
1010 == number 10
ook when the binary digit are same,
we get 0 as resut, when they toggle we get 1.
which means if toggle answre is 1 else 0
eg: 9^3 ==
1001
0011
------
1010 == number 10
ook when the binary digit are same,
we get 0 as resut, when they toggle we get 1.
Manoj said:
7 years ago
XOR means, the output will be 1 if both the input are exclusive i.e. both the input should be different for example (1, 0) (0, 1) so this gives output 1. Hence output of (1, 1) (0, 0) is 0.
Santhosh jaina said:
1 decade ago
Do smart work by looking at options we can say tht first three ans are lesser than 12 while doing OR operation the value will automatically increase.
Mahi said:
1 decade ago
11 == 1011
9 == 1001 & (AND)
----------
9 == 1001
3 == 0011 ^ (XOR)
----------
10 == 1010
12 == 1100 | (OR)
----------
14 == 1110
9 == 1001 & (AND)
----------
9 == 1001
3 == 0011 ^ (XOR)
----------
10 == 1010
12 == 1100 | (OR)
----------
14 == 1110
Iftekhar-ul-haque said:
5 years ago
11 == 1011
9 == 1001 & (AND)
----------
9 == 1001
3 == 0011 ^ (XOR)
----------
10 == 1010
12 == 1100 | (OR)
----------
14 == 1110.
9 == 1001 & (AND)
----------
9 == 1001
3 == 0011 ^ (XOR)
----------
10 == 1010
12 == 1100 | (OR)
----------
14 == 1110.
(2)
Accel said:
9 years ago
Thanks a lot, @Rashmi.
I didn't understand why 1 or 1 = 0, but you covered that up!
I didn't understand why 1 or 1 = 0, but you covered that up!
Sumit said:
1 decade ago
Please explain this clearly and complete. I can't understand what is happning.
Dheeraj Reddy said:
7 years ago
11= 1101.
9 = 1001.
9 = 1001.
3 = 0011.
10 = 1010.
12 = 1100.
14 = 1110.
9 = 1001.
9 = 1001.
3 = 0011.
10 = 1010.
12 = 1100.
14 = 1110.
(1)
S. Jasmine said:
2 decades ago
I can't understand that how this answer came, can somebody explain me?
Keerthana said:
6 years ago
Why we are choosing 9 as value for X? There is an another value 11.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers