Discussion :: Operators and Assignments
-
Which two are equal?
- 32/4
- (8 >> 2) << 4
- 2^5
- 128 >>> 2
- 2 >> 5
Answer : Option B
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).
Be The First To Comment