Skip to content
BetterDL

Range

Also called: representable range, number range, unsigned range, two's complement range, signed range

The smallest to largest value a format can represent in n bits: 0 to 2ⁿ − 1 unsigned, and −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1 in two's complement.

A fixed number of bits can only make so many patterns (2ⁿ for n bits), so every format has a range: the values it can show. Any result outside the range causes overflow.

The formulas for n bits:

Some values to know:

  • 4 bits: 0 to 15 unsigned, −8 to 7 signed
  • 8 bits: 0 to 255 unsigned, −128 to 127 signed
  • 16 bits: 0 to 65,535 unsigned, −32,768 to 32,767 signed

Why the − 1s? Unsigned: zero uses up one of the 2ⁿ patterns. Two's complement: half the patterns (MSB 1) are negative, and the other half hold zero and the positives, so the positive side ends one short. That's why −128 fits in 8 bits but +128 doesn't.

To find how many bits a value needs, look for the smallest n whose range contains it (see bit width).

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

Worked example

Example

Three ranges for 6 bits

6 bits give 2⁶ = 64 patterns.

  1. 1.

    Unsigned: 0 to 63. All 64 patterns are different values.

  2. 2.

    Two's complement: −32 to 31. Also 64 values.

  3. 3.

    Sign-magnitude: −31 to 31. Only 63 values, because 0 appears twice.

Common mistakes

  • Writing the unsigned range as 0 to 2ⁿ.

  • Making the two's complement range symmetric. −127 to 127 in 8 bits is sign-magnitude; two's complement reaches −128.

  • Confusing the number of values (2ⁿ) with the largest value.

Practice Range

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

Learn it step by step

Range is taught in Number Systems.