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?
  1. 16*4
  2. 16>>2
  3. 16/2^2
  4. 16>>>2
1 and 2
2 and 4
3 and 4
1 and 3
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.

Prajwal said:   10 years ago
This work in hexa-decimal format.

Ex: We have 16 >>> 2.

0000 0000 0001 0000 --> 16.

Then 16 shifted by 2.

0000 0000 0000 0100 --> 4.

Observe 1 is shifted by 2.

Abhi said:   10 years ago
The >>> operator shifts the bits of expression 1 right by the number of bits specified in expression 2. Zeroes are filled in from the left. Digits shifted off the right are discarded.

Eod said:   1 decade ago
@Venkat, '^' operation is not Math.Exp, as @Utpal said before it's bit wise OR operation.

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.

Isaac said:   1 decade ago
Which of these statements are equivalent 3/2, 3<2, 3*4, 3<<2.

Naveen said:   1 decade ago
Is correct. 16 >>> 2 = 4.

How it will come will you please provide mathamatically discription.

D.Sapna said:   1 decade ago
What is the difference between 16>>2 and 16>>>2?

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 ?

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.


Post your comments here:

Your comments will be displayed after verification.