Quiz Entry - updated: 2026.07.07
What is sign extension and when is it used?
To widen a signed value, copy its sign bit into all the new high bits — that keeps the number's value (and sign) unchanged.
* Widening from 4 to 8 bits: the new high bits are filled with copies of the sign bit, so +5 stays 00000101 and −5 stays 11111011. *
Used when converting a smaller signed type to a larger one.
Example: 4-bit → 8-bit
Positive: 0101 (+5) → 00000101 (+5)
Negative: 1011 (-5) → 11111011 (-5)
Rule: Copy the sign bit (MSB) into all new positions.
Why it works: The negative weight of the sign bit doubles with each added bit, but adding another copy of the sign bit compensates.
In C: Automatic when assigning char to int, short to long, etc.
Go deeper:
Sign extension (Wikipedia) — widening a value while preserving its sign and magnitude.