Java Programming - Operators and Assignments - Discussion

Discussion :: Operators and Assignments - Pointing out the correct statements (Q.No.4)

4. 

Which two statements are equivalent?

  1. 3/2
  2. 3<2
  3. 3*4
  4. 3<<2

[A]. 1 and 2
[B]. 2 and 3
[C]. 3 and 4
[D]. 1 and 4

Answer: Option C

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).


Firoz said: (Aug 17, 2012)  
I Can't Understand it. Explain clearly...

Raju Royal.Sp said: (Jul 2, 2013)  
@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.

Kallu said: (Feb 1, 2016)  
I am so dumb, can't understand that binary stuff.

Ganny said: (Feb 11, 2016)  
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.

Annu said: (Mar 27, 2016)  
Java 'Javac' command.

Nisha said: (Dec 14, 2016)  
I didn't understand that. Please help me.

Memr said: (Jan 19, 2017)  
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.

Priya said: (Apr 8, 2017)  
Once again please explain me clearly. I can't understand the given explanation.

Vishu said: (Feb 15, 2018)  
3 means in binary 0011.
shift 2 means 1100.
1100 means decimal 12.

Mon said: (Nov 21, 2019)  
Is this symbol << represents bitwise operators?

Mukesh Patel said: (Feb 10, 2020)  
The explanation is too good.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.