Java Programming - Operators and Assignments - Discussion
Discussion Forum : Operators and Assignments - Pointing out the correct statements (Q.No. 4)
4.
Which two statements are equivalent?
- 3/2
- 3<2
- 3*4
- 3<<2
Answer: Option
Explanation:
(1) is wrong. 3/2 = 1 (integer arithmetic).
(2) is wrong. 3 < 2 = false.
(3) is correct. 3 * 4 = 12.
(4) is correct. 3 <<2= 12. In binary 3 is 11, now shift the bits two places to the left and we get 1100 which is 12 in binary (3*2*2).
Discussion:
11 comments Page 1 of 2.
Mukesh Patel said:
6 years ago
The explanation is too good.
Mon said:
6 years ago
Is this symbol << represents bitwise operators?
Vishu said:
8 years ago
3 means in binary 0011.
shift 2 means 1100.
1100 means decimal 12.
shift 2 means 1100.
1100 means decimal 12.
Priya said:
8 years ago
Once again please explain me clearly. I can't understand the given explanation.
MeMr said:
9 years ago
Great explanation @Raju Royal & @Ganny.
So we need to change 3 to binary it's : 3 = 2 +1 = 1*2^1+1*2^0 => we've got 11 but also shift the bits two places to the left and we get 1100 which is 12.
So we need to change 3 to binary it's : 3 = 2 +1 = 1*2^1+1*2^0 => we've got 11 but also shift the bits two places to the left and we get 1100 which is 12.
Nisha said:
9 years ago
I didn't understand that. Please help me.
Annu said:
9 years ago
Java 'Javac' command.
Ganny said:
10 years ago
Just remember this thing : four digit binary == 8 4 2 1.
Ex:
3 you want binary value: Above series 3 will come by adding 1 and 2. So put 1 in place of 1 and 2, now 3 binary will look like 0011. Now come into question he is shifting two bits right side so becomes 1100 means 12.
So we are already know that 2^0*0 + 2^1*0 + 2^2*1 +2^3*1 = 12. So finally concluded that 3*4 and 3 << 2 are equals.
Ex:
3 you want binary value: Above series 3 will come by adding 1 and 2. So put 1 in place of 1 and 2, now 3 binary will look like 0011. Now come into question he is shifting two bits right side so becomes 1100 means 12.
So we are already know that 2^0*0 + 2^1*0 + 2^2*1 +2^3*1 = 12. So finally concluded that 3*4 and 3 << 2 are equals.
Kallu said:
10 years ago
I am so dumb, can't understand that binary stuff.
Raju royal.sp said:
1 decade ago
@Firoj.
This is not critical problem observe clearly if the given equation can be solve first then you will identified easily,
(1) 3/2 = 1.5
(2) 3<2 this is false because 3 is not lesser than 2
(3) 3*4 = 12
(4) 3 <<2 means if the binary value of 3 is 11
i.e 1*2^1+1*2^0 = 2+1 = 3.
<< means get 00 to the right side of 11.
So 1100 means 12.
So 3 and 4 are equal that's why answer is C.
This is not critical problem observe clearly if the given equation can be solve first then you will identified easily,
(1) 3/2 = 1.5
(2) 3<2 this is false because 3 is not lesser than 2
(3) 3*4 = 12
(4) 3 <<2 means if the binary value of 3 is 11
i.e 1*2^1+1*2^0 = 2+1 = 3.
<< means get 00 to the right side of 11.
So 1100 means 12.
So 3 and 4 are equal that's why answer is C.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers