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 1 of 3.

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

How it will come will you please provide mathamatically discription.

Sneha said:   1 decade ago
I also wanna know the same thing..

Badri said:   1 decade ago
Please explain the above expression (such as 16>>>2).

Hareram said:   1 decade ago
Please explain it detail how. ?

Khyati said:   1 decade ago
In binary 16 is 10000, now shift the bits two places to the right (>>2)and we get 100 which is 4.

Anil said:   1 decade ago
In binary 16 is 10000, now shift the bits two places to the right (>>2)and we get 100 which is 4

In binary 16 is 10000, now shift the bits three places to the right (>>>2)and we get 10 which is 2

So how the 2 and 4 is correct?

Jose Marti said:   1 decade ago
Because the unsigned right shift operator ">>>" shifts a ZERO into the leftmost position.

In binary 16 is 10000, now shift the bits two places to the right. We get 100. Then add a 0 into the leftmost position, we get 0100 which is 4.
(2)

Rohan said:   1 decade ago
Thanks Jose.

BIKASH DEY said:   1 decade ago
Can any one tell me mathematically how is 16/2 ^ 2 = 10.

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.