Java Programming - Operators and Assignments - Discussion
Discussion Forum : Operators and Assignments - Pointing out the correct statements (Q.No. 3)
3.
Which two statements are equivalent?
- 16*4
- 16>>2
- 16/2^2
- 16>>>2
Answer: Option
Explanation:
(2) is correct. 16 >> 2 = 4
(4) is correct. 16 >>> 2 = 4
(1) is wrong. 16 * 4 = 64
(3) is wrong. 16/2 ^ 2 = 10
Discussion:
27 comments Page 2 of 3.
Venkat said:
1 decade ago
Guys can you please explain about third option "(3) is wrong, 16/2^2 = 10" how?
Kumari.N said:
1 decade ago
3/2 = 1 (Integer arthimetic).
3<2 = false.
3*4 = 12.
3<<2 = 12 In binary 3 is 11 and left shift 11 to two places that is 1100.
Which is equal to 12.
3<2 = false.
3*4 = 12.
3<<2 = 12 In binary 3 is 11 and left shift 11 to two places that is 1100.
Which is equal to 12.
Isaac said:
1 decade ago
Which of these statements are equivalent 3/2, 3<2, 3*4, 3<<2.
Asmat said:
1 decade ago
16>>2 signed right shift.
16>>>2 unsigned right shift.. the most significant bit in >> is sign bit, so that if the sign bit is 0, the number is positive and if the sign bit is 1 the number is negative.
Here since the number is already positive when we shift by >>, we get 100 and when we use >>> we get 0100, the 0 before 1 represents that its a positive number..Had this been -16, the answer would have been 100 for >> and 1100 for >>>.
16>>>2 unsigned right shift.. the most significant bit in >> is sign bit, so that if the sign bit is 0, the number is positive and if the sign bit is 1 the number is negative.
Here since the number is already positive when we shift by >>, we get 100 and when we use >>> we get 0100, the 0 before 1 represents that its a positive number..Had this been -16, the answer would have been 100 for >> and 1100 for >>>.
D.Sapna said:
1 decade ago
What is the difference between 16>>2 and 16>>>2?
Utpal Sharma said:
1 decade ago
In java >> and >>> both have same meaning right shift and 16/2^2 here first 16/2=8 and then 8^2 perform bitwise OR operation so 8 in binary 1000, 2 is 0010 output is 1010 which is 10.
(1)
Mukesh said:
1 decade ago
For 16>>2=4 is OK but still I am not getting how you did 16>>>2 =4.
What is the meaning of three >>> symbols. Two >> means bit-wise shifting. What is the meaning of X>>>y ?
What is the meaning of three >>> symbols. Two >> means bit-wise shifting. What is the meaning of X>>>y ?
Mmintz01 said:
1 decade ago
16/2 equals 8 so in binary represents the number 1000 if you xor (8^2) this with 2 in binary meaning 0010 you have 1010 in binary which is 10 in decimal system.
BIKASH DEY said:
1 decade ago
Can any one tell me mathematically how is 16/2 ^ 2 = 10.
Rohan said:
1 decade ago
Thanks Jose.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers