Engineering Programming (MATLAB/Python) · Problem type

The range of an integer type

Use this for “What values fit in an int8, and in a uint8?”

Diagram

sign7value bits7 bits60Value 12701111111
sign 1 + value bits 7 = 8 bits, the whole 8-bit word.
Signed least min = −128
Unsigned largest maxᵤ = 255
This is an example. Type your own values to start a new problem.
min
≤
int
n
≤
max
0
≤
uint
n
≤
maxᵤ

Formulas

min
=
−
2
n
− 1
−128
=
−
2
8 − 1
max
=
2
n
− 1
−
1
127
=
2
8 − 1
−
1
maxᵤ
=
2
n
−
1
255
=
2
8
−
1

Assumptions

•
Integer types come in 8, 16, 32 and 64 bits: int8 to int64, uint8 to uint64.
•
Unsigned types run from 0; signed types use two’s complement, so the top bit weighs −2ⁿ⁻¹.
•
A value past either end does not fit: MATLAB saturates at the end, NumPy wraps round.

Step-by-step

WE KNOW
n = 8
FIND
signed least (min), signed largest (max), unsigned largest (maxᵤ)
Step 1 · Find signed least (min)
Use min = −2ⁿ⁻¹
Two’s complement gives half the 2ⁿ patterns to negatives, down to −2ⁿ⁻¹.
min
=
−
2
8 − 1
8-bit
signed,
least:
−
2
7
=
−128
min = −128
Step 2 · Find signed largest (max)
Use max = 2ⁿ⁻¹ − 1
The other half of the patterns are 0 and the positives, so the top is one short of 2ⁿ⁻¹.
max
=
2
8 − 1
−
1
8-bit
signed,
largest:
2
7
−
1
=
127
max = 127
Step 3 · Find unsigned largest (maxᵤ)
Use maxᵤ = 2ⁿ − 1
All 2ⁿ patterns count up from 0, so the largest is one short of 2ⁿ.
maxᵤ
=
2
8
−
1
8-bit
unsigned,
largest:
2
8
−
1
=
255
maxᵤ = 255
Check
Put the numbers back in. Both sides should match.
−128
=
−
2
8 − 1
✓
127
=
2
8 − 1
−
1
✓
255
=
2
8
−
1
✓
Topic check
See what you know: 5 questions on this topic
New questions each time. Pass to mark it complete.

Related lessons

© 2026 SME. All rights reserved.