Skip to content
BetterDL

Sign extension

Also called: sign extend, sign extending

Widening a two's complement number to more bits by copying its sign bit into every new position on the left, which keeps its value the same.

Sign extension makes a twos complement number wider without changing its value: copy the MSB into every new bit on the left.

  • 4-bit 0101 (+5) → 8-bit 00000101 (+5)
  • 4-bit 1101 (−3) → 8-bit 11111101 (−3)

Why it works: in 4 bits the MSB of 1101 is worth −8. In 8 bits the new MSB is worth −128, and the copied 1s below it add 64 + 32 + 16 + 8 = 120. Together they make −128 + 120 = −8, exactly the old MSB's weight. The other bits are untouched, so the value is unchanged.

On the counter picture, −3 is "three steps back from zero" at any width: 1101 in 4 bits, 11111101 in 8 bits.

In hex, look at the top digit. If it's 8–F (MSB 1), pad with F's. If it's 0–7, pad with 0's. So 8-bit 9E₁₆ becomes FF9E₁₆, and 5A₁₆ becomes 005A₁₆.

Where it shows up: loading a signed byte into a 32-bit register, or adding numbers of different widths. Unsigned values are widened with zeros instead (zero extension), so processors usually have a signed and an unsigned version of each narrow load.

1
−128
1
64
1
32
1
16
1
8
1
4
0
2
1
1

Worked examples

Example

Extend 5-bit 10011 to 8 bits

Copy the MSB (1) into the three new bits.

  1. 1.

    Original value: −16 + 2 + 1 = −13.

  2. 2.

    Extended: 11110011.

  3. 3.

    Check: −128 + 64 + 32 + 16 + 2 + 1 = −13. Same value.

Example

Extend 8-bit 9E₁₆ to 16 bits

The top digit 9 is 8–F, so the MSB is 1 and each new digit is F: FF9E₁₆. Check: 9E₁₆ = 158, and 158 − 256 = −98. FF9E₁₆ = 65,438, and 65,438 − 65,536 = −98.

Common mistakes

  • Padding a negative number with zeros: 00001101 is +13, not −3.

  • Sign-extending an unsigned number. Unsigned values are padded with zeros.

  • Copying the wrong bit. Copy the MSB of the original width.

Practice Sign extension

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Sign extension is taught in Number Systems.