Welcome Guest | Sign in | Register
Operators and Assignments - Discussion Page For Q.2928 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Operators and Assignments > Questions and Answers

Exercise:

Section 1

Q:  Which two are equal?
1. 32/4
2. (8 >> 2) << 4
3. 2^5
4. 128 >>> 2
5. 2 >> 5
A. 1 and 2 B. 2 and 4
C. 1 and 3 D. 2 and 3

Answer and Explanation

Answer:2 and 4

Explanation:
(2) and (4) are correct. (2) and (4) both evaluate to 32. (2) is shifting bits right then left using the signed bit shifters >> and <<. (4) is shifting bits using the unsigned operator >>>, but since the beginning number is positive the sign is maintained.
(1) evaluates to 8, (3) looks like 2 to the 5th power, but ^ is the Exclusive OR operator so (3) evaluates to 7. (5) evaluates to 0 (2 >> 5 is not 2 to the 5th).

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.