Skip to content
BetterDL

Signed vs unsigned

Also called: signed versus unsigned, unsigned vs signed, signed and unsigned

The same bit pattern means different values depending on whether it's read as unsigned (all weights positive) or signed two's complement (MSB negative).

Bits have no built-in meaning. The 8-bit pattern 11111111 is 255 read as unsigned and −1 read as twos complement. Which is right depends only on what the program intends.

What stays the same:

  • patterns with MSB 0 mean the same value in both readings
  • addition and subtraction produce identical bits for both, so one adder serves both

What differs:

  • patterns with MSB 1: the signed value is the unsigned value minus 2ⁿ
  • the range: 0 to 2ⁿ − 1, versus −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1
  • the overflow test: the carry out for unsigned, the sign rule (V) for signed
  • comparisons: 1000 > 0111 unsigned (8 > 7), but 1000 < 0111 signed (−8 < 7)
  • widening: zeros for unsigned, sign extension for signed

That's why processors keep both a carry flag and an overflow flag, and why languages like C have both int8_t and uint8_t. The hardware computes the bits once; the program decides which reading to trust.

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

Worked example

Example

One addition, two verdicts

4-bit 1011 + 0110 = 1 0001.

  1. 1.

    Unsigned: 11 + 6 = 17, which doesn't fit. The carry-out is 1, and the 4 bits show 1. Overflow.

  2. 2.

    Signed: −5 + 6 = 1, and 0001 = 1. Correct, and V = 0.

  3. 3.

    Same bits, opposite verdicts. The flag you check must match the data type.

Common mistakes

  • Asking whether a pattern "is" signed. Ask how it's being read.

  • Using the carry-out to judge a signed result, or V to judge an unsigned one.

  • Comparing signed values with unsigned rules.

Practice Signed vs unsigned

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

Learn it step by step

Signed vs unsigned is taught in Number Systems and Adders and ALUs.