DE Notes
Understand signed and unsigned binary number representations including sign-magnitude, 1
In digital systems, we need to represent both positive and negative numbers using only 0s and 1s. The distinction between signed and unsigned interpretation of binary data is fundamental to computer architecture and programming.
Unsigned Numbers
Unsigned numbers represent only non-negative values (zero and positive integers). All bits contribute to the magnitude.
Range of Unsigned Numbers
For an n-bit unsigned number:
- Minimum value: 0
- Maximum value: 2ⁿ - 1
- Total values: 2ⁿ
| Bits | Range | Example |
|---|---|---|
| 4 | 0 to 15 | 1111 = 15 |
| 8 | 0 to 255 | 11111111 = 255 |
| 16 | 0 to 65,535 | |
| 32 | 0 to 4,294,967,295 |
Conversion Example
Comparison of All Three Methods (4-bit)
| Decimal | Sign-Magnitude | 1's Complement | 2's Complement |
|---|---|---|---|
| +7 | 0111 | 0111 | 0111 |
| +6 | 0110 | 0110 | 0110 |
| +5 | 0101 | 0101 | 0101 |
| +4 | 0100 | 0100 | 0100 |
| +3 | 0011 | 0011 | 0011 |
| +2 | 0010 | 0010 | 0010 |
| +1 | 0001 | 0001 | 0001 |
| +0 | 0000 | 0000 | 0000 |
| -0 | 1000 | 1111 | — |
| -1 | 1001 | 1110 | 1111 |
| -2 | 1010 | 1101 | 1110 |
| -3 | 1011 | 1100 | 1101 |
| -4 | 1100 | 1011 | 1100 |
| -5 | 1101 | 1010 | 1011 |
| -6 | 1110 | 1001 | 1010 |
| -7 | 1111 | 1000 | 1001 |
| -8 | — | — | 1000 |
Sign Extension
When converting a signed number to a larger bit width, you must extend the sign bit.
2's Complement Sign Extension
| +5 in 4 bits | 0101 |
| +5 in 8 bits | 0000 0101 (extend with 0s) |
| -3 in 4 bits | 1101 |
| -3 in 8 bits | 1111 1101 (extend with 1s) |
Rule: Copy the MSB (sign bit) into all new higher-order positions.
Why Sign Extension Works
Unsigned vs Signed: Same Bits, Different Values
The bit pattern doesn't change — only the interpretation matters:
| Bit Pattern | Unsigned Value | Signed (2's Comp) Value |
|---|---|---|
| 0000 0000 | 0 | 0 |
| 0111 1111 | 127 | +127 |
| 1000 0000 | 128 | -128 |
| 1111 1111 | 255 | -1 |
| 1100 0000 | 192 | -64 |
This is why programming languages distinguish between int (signed) and unsigned int.
Detecting Overflow
Unsigned Overflow
Occurs when carry out of the MSB exists.
Signed Overflow
Occurs when two numbers of the same sign produce a result of opposite sign.
Overflow Detection Formula: V = Cₙ ⊕ Cₙ₋₁ (XOR of carry into MSB and carry out of MSB)
ASCII Diagram: Number Line Representation
Practical Applications
| Application | Representation Used | Why |
|---|---|---|
| Memory addresses | Unsigned | Addresses are never negative |
| Pixel colors (RGB) | Unsigned | 0-255 range needed |
| Temperature | Signed | Can be negative |
| Audio samples | Signed | Oscillates around zero |
| Array indices | Unsigned | Indices start at 0 |
Interview Questions
Q1: What is the difference between signed and unsigned overflow?
Unsigned overflow is detected by carry out of the MSB. Signed overflow is detected when the carry into the MSB differs from the carry out (V = Cₙ ⊕ Cₙ₋₁). The same addition can overflow in one interpretation but not the other.
Q2: Why do most processors use 2's complement for signed integers?
Because: (1) unique zero representation simplifies comparisons, (2) the same addition hardware works for both signed and unsigned, (3) no end-around carry needed, and (4) one extra negative value gives slightly larger range.
Q3: How does sign extension preserve the value of a number?
By replicating the sign bit into all new upper positions. Mathematically, for 2's complement, this works because adding higher-order 1s to a negative number contributes -2ⁿ + 2ⁿ⁻¹ + ... which equals the same negative weight at the new MSB position.
Q4: What is the result of interpreting 1010 1010 as unsigned vs signed?
Unsigned: 128 + 32 + 8 + 2 = 170. Signed (2's complement): -128 + 32 + 8 + 2 = -86. Same bits, different values depending on interpretation.
Q5: In C programming, what happens when you assign -1 to an unsigned variable?
The bit pattern of -1 in 2's complement (all 1s) is reinterpreted as unsigned. For a 32-bit unsigned int, -1 becomes 4,294,967,295 (2³² - 1). The bits don't change — only the interpretation does.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Signed and Unsigned Numbers in Binary Representation.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Digital Electronics topic.
Search Terms
digital-electronics, digital electronics, digital, electronics, number, systems, signed, and
Related Digital Electronics Topics