Multiple choice technology programming languages

The operations y >> 3 and y >>> 3 produce the same result when y > 0.

  1. True

  2. False

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

For positive numbers (y > 0), both >> (signed right shift) and >>> (unsigned right shift) produce identical results. When the number is positive, the sign bit is 0, so both operators insert 0 bits from the left. For example: 40 >> 3 = 5 and 40 >>> 3 = 5. The difference appears only with negative numbers.

AI explanation

True. In Java (and similar C-family languages), >> is the arithmetic (signed) right shift, which fills vacated high-order bits with copies of the sign bit, while >>> is the logical (unsigned) right shift, which always fills vacated bits with 0. For a positive value y (y > 0), the sign bit is already 0, so sign-extension and zero-fill produce identical bit patterns — the two operators behave the same. They only diverge for negative y, where >> preserves the negative sign (fills with 1s) and >>> produces a large positive number (fills with 0s).