← 🔢 Number Representation & Computer Arithmetic
Subtopic 3 of 9

4.3Sign extension

The idea

Sign extension widens a signed number by copying its sign bit into the new high bits, so the value does not change.

Think of it like this: Writing −5 as −0005: you add leading digits that match the sign without changing the number.

Why it exists

Registers and operands have different widths, and values must keep their meaning when widened.

How it works

  1. Take the original n bits.
  2. Replicate the top (sign) bit into the new upper bits.
  3. Positive numbers get 0s, negative get 1s.
  4. Zero-extension is for unsigned numbers only.

Worked example: 4-bit 1011 (−5) to 8 bits

Copy the 1: 1111 1011 which is still −5.

Now play with it

  • →Extend −5 to 8 then 16 bits, then tick "zero-extend" and see the value become wrong.
11111011

Gold = new bits, each a copy of the sign bit (1). Value now: -5 (preserved)

Check yourself

The 4-bit 2's complement number 1010 is sign-extended to 8 bits. What is the result?

Remember: Sign extension copies the sign bit; zero extension is for unsigned.
Exam notes (the dense version)

Copy the MSB into new high bits to keep value when widening a 2's complement number.

Previous year questions: Number Representation & Computer Arithmetic (19)

PYQs are grouped by topic, so this is the full set for Number Representation & Computer Arithmetic; try the ones that match this subtopic. Open all 19 on the topic page.