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 3 of 4.
John said:
1 decade ago
8421
1011
1001
====
1001=9
0011
====
1010=10
1100
====
1110=14
1011
1001
====
1001=9
0011
====
1010=10
1100
====
1110=14
Ashu said:
8 years ago
What should be done when 1100|0011?
How the String is done?
How the String is done?
Sudarshan said:
1 decade ago
1001 = (x=9)
0011 = 3
1010 = (y=9^3)
1100 = 12
1110 = y|12
0011 = 3
1010 = (y=9^3)
1100 = 12
1110 = y|12
Sunny deol said:
9 years ago
Agree @Suresh.
I think 15 is the correct answer.
I think 15 is the correct answer.
Buck said:
8 years ago
Very well explained @ Rashmi and @Suresh.
Prudhvi said:
8 years ago
Well explained, thanks @Jitesh Powankar.
(2)
Mansi jain said:
1 decade ago
What the function ^ is does ?
Joginder sharma said:
1 decade ago
Thanks Sudarshan and Satish.
Jaz said:
1 decade ago
Well anyone make more clear.
Sachin J said:
9 years ago
Thank you @Jaishriram.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers