Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which two statements are equivalent?

1.16*4

2.16>>2

3.16/2^2

4.16>>>2

  • A.1 and 2
  • B.2 and 4
  • C.3 and 4
  • D.1 and 3

Answer: B

Correct answer: 2 and 4

\( 16 \gg 2 \) and \( 16 \ggg 2 \) both give 4: for a positive value the arithmetic and logical right shifts are identical, since the sign bit being shifted in is zero either way. \( 16 \times 4 \) is 64, and \( 16/2^{\wedge}2 \) is not 4 either - division binds tighter than the bitwise exclusive-or, so it evaluates as \( (16/2) \wedge 2 = 8 \wedge 2 = 10 \). The caret is XOR in Java, not exponentiation.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.