# Binary representation of integers

> CIE A-Level Computer Science · 9618
> Source: https://www.owlsprep.com/study/cie-9618-u1-binary-representation-of-integers/

This sub-topic covers how integers are stored as binary in computer systems. You will learn conversion between decimal and binary, and find the range of values for any bit length for both unsigned and signed integers.

**Prerequisites:** Basic understanding of base 10 (decimal) number system

## Learning objectives

- Convert between binary and decimal for unsigned and two's complement integers
- Calculate the range of values and number of unique values for a given bit length
- Distinguish between unsigned and signed two's complement binary representations
- Identify and avoid common exam errors in range calculations and conversion

## Unsigned Binary Integers

**Unsigned Binary Integer** — Representation of non-negative integers where each bit is weighted by a power of 2, starting from $2^0$ at the rightmost least significant bit.

*Notation:* n-bit unsigned

*Example:* 4-bit unsigned can represent 0 through 15

To convert an unsigned binary number to decimal, multiply each bit by its weight and sum the results. To convert decimal to unsigned binary, repeatedly divide by 2, collect remainders, then reverse the order of remainders.

**Worked example:** Convert the 5-bit unsigned binary $10110_2$ to decimal

1. Label each bit with its weight starting from $2^0$ at the right:
2. $$\text{Bit}: 1 \quad 0 \quad 1 \quad 1 \quad 0 \\ \text{Weight}: 2^4 \quad 2^3 \quad 2^2 \quad 2^1 \quad 2^0 = 16 \quad 8 \quad 4 \quad 2 \quad 1$$
3. Multiply each bit by its weight and sum:
4. $$(1 \times 16) + (0 \times 8) + (1 \times 4) + (1 \times 2) + (0 \times 1) = 22$$

> **Exam tip:** Always count bit positions starting from 0 at the right, not 1, to avoid incorrect weight calculations.

## Range of Unsigned Binary Integers

For n-bit unsigned binary, every combination of bits maps to a unique non-negative integer. The smallest value is 0 (all bits 0) and the largest value occurs when all bits are 1.

**Range of n-bit unsigned binary** — Total unique values = $2^n$. Range of values is $0$ to $2^n - 1$ inclusive.

**Worked example:** Find the range of 6-bit unsigned binary integers, how many unique values can it store?

1. Calculate total unique values for n=6 bits:
2. $$2^n = 2^6 = 64$$
3. The maximum value is one less than the total number of values, since we start counting from 0:
4. $$\text{Minimum} = 0, \quad \text{Maximum} = 64 - 1 = 63$$
5. Final result: 6-bit unsigned can store 64 unique values ranging from 0 to 63.

> **Exam tip:** CIE often asks for maximum value, not number of values — always remember to subtract 1 from $2^n$.

## Signed Binary: Two's Complement

CIE 9618 exclusively tests two's complement for signed binary integers, which can represent both positive and negative values. The leftmost (most significant) bit has a negative weight, all other bits have positive weights.

**Two's Complement Signed Integer** — Signed binary representation where the leftmost bit has weight $-2^{n-1}$, and all other bits follow standard unsigned weighting. This simplifies binary arithmetic.

*Notation:* n-bit two's complement

**Worked example:** Convert 5-bit two's complement $11010_2$ to decimal

1. Calculate the negative weight for the leftmost bit:
2. $$n=5, \quad \text{Leftmost weight} = -2^{5-1} = -16$$
3. List all bits and their weights:
4. $$\text{Bit}: 1 \quad 1 \quad 0 \quad 1 \quad 0 \\ \text{Weight}: -16 \quad 8 \quad 4 \quad 2 \quad 1$$
5. Sum the weighted bits to get the final decimal value:
6. $$(1 \times -16) + (1 \times 8) + (0 \times 4) + (1 \times 2) + (0 \times 1) = -6$$

> **Exam tip:** Never forget the negative weight on the leading bit — this is the most common error in two's complement conversion.

## Range of Two's Complement Integers

One bit is reserved for the sign in two's complement, so the range is shifted to include negative values. The total number of unique values remains $2^n$, same as unsigned for the same bit length.

**Range of n-bit two's complement** — Minimum (most negative) value = $-2^{n-1}$, maximum (most positive) value = $2^{n-1} - 1$, with $2^n$ total unique values.

**Worked example:** What is the range of 8-bit two's complement signed integers?

1. Use the range formula for n=8 bits:
2. $$\text{Minimum} = -2^{n-1} = -2^{7} = -128$$
3. $$\text{Maximum} = 2^{n-1} - 1 = 2^7 - 1 = 127$$
4. Final range: 8-bit two's complement can represent all integers from -128 to 127 inclusive, with 256 total unique values.

## Common pitfalls

- **Wrong:** Stating the maximum value of n-bit unsigned binary as $2^n$
  - Why it fails: The range starts at 0, so the maximum value is one less than the total number of possible bit combinations
  - Correct: Maximum value for n-bit unsigned binary is $2^n - 1$
- **Wrong:** Giving the range of 8-bit two's complement as -127 to 128
  - Why it fails: The most negative value is $-2^{n-1}$, while the maximum is $2^{n-1} - 1$, so the negative range extends one further than the positive
  - Correct: Range of 8-bit two's complement is $-128 \leq x \leq 127$
- **Wrong:** Using a positive weight for the leading bit when converting two's complement
  - Why it fails: The entire purpose of two's complement is to use a negative leading bit to represent negative values
  - Correct: Always multiply the leftmost bit of n-bit two's complement by $-2^{n-1}$
- **Wrong:** Counting bit positions starting from 1 instead of 0 when calculating weights
  - Why it fails: The rightmost bit is $2^0$, so shifting all positions by 1 gives an incorrect weight for every bit
  - Correct: Start counting positions from 0 at the rightmost least significant bit
- **Wrong:** Claiming 4-bit unsigned can represent 16 values from 1 to 16
  - Why it fails: 0 is a valid integer that requires a representation, so the range always starts at 0 for unsigned binary
  - Correct: 4-bit unsigned ranges from 0 to 15, with 16 total unique values

## Cheatsheet

| Representation | Total unique values | Minimum value | Maximum value |
| --- | --- | --- | --- |
| n-bit unsigned | $2^n$ | $0$ | $2^n - 1$ |
| 4-bit unsigned | 16 | $0$ | $15$ |
| 8-bit unsigned | 256 | $0$ | $255$ |
| n-bit two's complement | $2^n$ | $-2^{n-1}$ | $2^{n-1} - 1$ |
| 4-bit two's complement | 16 | $-8$ | $7$ |
| 8-bit two's complement | 256 | $-128$ | $127$ |

## What's next

Binary integer representation is the foundational concept for all data storage in computer systems, and all subsequent topics in information representation build on this knowledge. Understanding bit length and range is critical for binary arithmetic, overflow errors, memory addressing, and representing other data types like fractions, text, images, and sound. Mastery of this sub-topic will make more advanced number representation concepts much easier to learn, and it appears in at least one question on almost every CIE 9618 Paper 1 exam.

- [Binary representation of real numbers](https://www.owlsprep.com/study/cie-9618-u1-binary-representation-of-real-numbers/)
- [Character encoding](https://www.owlsprep.com/study/cie-9618-u1-character-encoding/)
- [Binary representation of images](https://www.owlsprep.com/study/cie-9618-u1-binary-representation-of-images/)

---

From [OwlsPrep](https://www.owlsprep.com) — free study guides for A-Level, IB, AP and IGCSE, written against the official syllabus. Canonical page: https://www.owlsprep.com/study/cie-9618-u1-binary-representation-of-integers/
