SME
Digital Logic Design · Problem type
Signed and unsigned ranges, overflow
Use this for “What range do 8 bits hold, signed and unsigned? What does 100 + 50 give in 8-bit signed?”
This is an example. Type your own values to start a new problem.
n
Width in bits
example
Uₘₐₓ
Largest unsigned
worked out (not typed)
Sₘᵢₙ
Least signed
worked out (not typed)
Sₘₐₓ
Largest signed
worked out (not typed)
A
First number
example
B
Second number
example
S
True sum
worked out (not typed)
W
Stored n-bit sum
worked out (not typed)
O
Overflow
worked out (not typed)
Formulas
Uₘₐₓ
=
2
n
−
1
255
=
2
8
−
1
Sₘᵢₙ
=
−
2
n
− 1
−128
=
−
2
8 − 1
Sₘₐₓ
=
2
n
− 1
−
1
127
=
2
8 − 1
−
1
S
=
A
+
B
150 = 100 + 50
O
:
compare
S
with
Sₘᵢₙ
and
Sₘₐₓ
150 > 127, so positive overflow
W
=
S
−
2
n
−106
=
150
−
2
8
Assumptions
•
Unsigned n bits hold 0 to 2ⁿ − 1; two’s complement n bits hold −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1.
•
The adder keeps only n bits, so a sum outside the signed range wraps by 2ⁿ.
•
Overflow happens only when both numbers have the same sign and the sum’s sign differs.
Step-by-step
WE KNOW
n = 8, A = 100, B = 50
FIND
largest unsigned (Uₘₐₓ), least signed (Sₘᵢₙ), largest signed (Sₘₐₓ), true sum (S), overflow (O), stored n-bit sum (W)
Step 1 · Find largest unsigned (Uₘₐₓ)
Use Uₘₐₓ = 2ⁿ − 1
n
bits
have
2ⁿ
patterns;
unsigned,
they
count
from
0,
so
the
largest
is
one
less.
Uₘₐₓ
=
2
8
−
1
8-bit
unsigned,
largest:
2
8
−
1
=
255
Uₘₐₓ = 255
Step 2 · Find least signed (Sₘᵢₙ)
Use Sₘᵢₙ = −2ⁿ⁻¹
The top bit weighs −2ⁿ⁻¹; with every other bit 0, that is the least value.
Sₘᵢₙ
=
−
2
8 − 1
8-bit
signed,
least:
−
2
7
=
−128
Sₘᵢₙ = −128
Step 3 · Find largest signed (Sₘₐₓ)
Use Sₘₐₓ = 2ⁿ⁻¹ − 1
Half the patterns are negative; the top bit 0 and the rest 1 is the largest.
Sₘₐₓ
=
2
8 − 1
−
1
8-bit
signed,
largest:
2
7
−
1
=
127
Sₘₐₓ = 127
Step 4 · Find true sum (S)
Use S = A + B
The
sum
as
the
numbers
really
add,
before
the
adder
drops
the
carry
out
of
bit
n
−
1.
S
=
100
+
50
S
=
150
Step 5 · Find overflow (O)
Use O: compare S with Sₘᵢₙ and Sₘₐₓ
The
true
sum
is
above
the
largest
signed
value,
so
n
bits
cannot
hold
it.
150 > 127: positive overflow
O
=
compare
150
with
−128
and
127
O
=
positive
overflow
Step 6 · Find stored n-bit sum (W)
Use W = S − 2ⁿ
The carry out of the top bit is lost, so the stored sum is 2ⁿ less.
W
=
150
−
2
8
W
=
150
−
256
W
=
−106
Check
Put the numbers back in. Both sides should match.
255
=
2
8
−
1
✓
−128
=
−
2
8 − 1
✓
127
=
2
8 − 1
−
1
✓
150 = 100 + 50 ✓
150 > 127, so positive overflow ✓
−106
=
150
−
2
8
✓
Topic check
See what you know: 5 questions on this topic
New questions each time. Pass to mark it complete.