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.
Sunny deol said:
9 years ago
Agree @Suresh.
I think 15 is the correct answer.
I think 15 is the correct answer.
Divyadharshini said:
8 years ago
Thanks a lot @John.
Ranjitha said:
8 years ago
Thanks for this.
Buck said:
8 years ago
Very well explained @ Rashmi and @Suresh.
Ashu said:
8 years ago
What should be done when 1100|0011?
How the String is done?
How the String is done?
Raghavendar said:
8 years ago
int x=9&11;
& ---->And operation means both are true then output is true otherwise false
so 9----->1001(binary form)
11---->1011
----------------------------------------
1001 so it's----->9
------------------------------------------------
y=x^3
^ ------->XOR operation so if both inputs are same then output is false otherwise false
So, x value is 9 binary is----1001.
y=1001^0011=1010 (decimal is 10)
then;
y|12
-----------> |-- OR operation means if both inputs are false then the output is false otherwise true.
y value----->1010
12 binary-> 1100
----------------------------------
1110 ------->14.
So the answer is 14.
& ---->And operation means both are true then output is true otherwise false
so 9----->1001(binary form)
11---->1011
----------------------------------------
1001 so it's----->9
------------------------------------------------
y=x^3
^ ------->XOR operation so if both inputs are same then output is false otherwise false
So, x value is 9 binary is----1001.
y=1001^0011=1010 (decimal is 10)
then;
y|12
-----------> |-- OR operation means if both inputs are false then the output is false otherwise true.
y value----->1010
12 binary-> 1100
----------------------------------
1110 ------->14.
So the answer is 14.
Prudhvi said:
8 years ago
Well explained, thanks @Jitesh Powankar.
(2)
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)
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.
Sneha sonawane said:
7 years ago
x=11&9 ie 1011(11) & 1001 (9) =1001 (9) //Binary conversions therefore now x=9;
y=x^3 ie 9^3 (^ is Ex OR operation) 1001^0011= 1010 (10) // Binary conversions therefore now y=10;.
y|12 ie 10|12 ( | is OR operator) 1010 | 1100 =1110 (14) ///Binary conversions therefore now y=14;
y=x^3 ie 9^3 (^ is Ex OR operation) 1001^0011= 1010 (10) // Binary conversions therefore now y=10;.
y|12 ie 10|12 ( | is OR operator) 1010 | 1100 =1110 (14) ///Binary conversions therefore now y=14;
(4)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers