# Proof of max integer encoded by two's complement

17 May 2015

Two’s-complement is the most common binary way of encoding positive and negative integers in computers. In this post I will prove that the maximum integer encoded by $n$ bits using two’s complement encoding is:

The two’s complement encoding ($TC$), implements the normal binary system except the most significant bit has a negative weight. Here are some examples with 4 bits:

$TC([{\color{#CC0000} {0001} }]) = −{\color{#CC0000} {0} } \cdot 2^3 + {\color{#CC0000} {0} } \cdot 2^2 + {\color{#CC0000} {0} } \cdot 2^1 + {\color{#CC0000} {1} } \cdot 2^0 = 0 + 0 + 0 + 1 = 1$ $TC([{\color{#CC0000} {0101} }]) = −{\color{#CC0000} {0} } \cdot 2^3 + {\color{#CC0000} {1} } \cdot 2^2 + {\color{#CC0000} {0} } \cdot 2^1 + {\color{#CC0000} {1} } \cdot 2^0 = 0 + 4 + 0 + 1 = 5$ $TC([{\color{#CC0000} {1011} }]) = −{\color{#CC0000} {1} } \cdot 2^3 + {\color{#CC0000} {0} } \cdot 2^2 + {\color{#CC0000} {1} } \cdot 2^1 + {\color{#CC0000} {1} } \cdot 2^0 = −8 + 0 + 2 + 1 = −5$ $TC([{\color{#CC0000} {1111} }]) = −{\color{#CC0000} {1} } \cdot 2^3 + {\color{#CC0000} {1} } \cdot 2^2 + {\color{#CC0000} {1} } \cdot 2^1 + {\color{#CC0000} {1} } \cdot 2^0 = −8 + 4 + 2 + 1 = −1$

Therefore the maximum integer encodable with 4 bits is 7:

Therefore for $n$ bits, the largest number encodable $MaxInt(n)$ is the sum of the base 2 bits excluding the left most bit:

For brevity, let us refer to the $MaxInt(n)$ sum as $S(n)$ for now:

Applying the proof of the geometric series to this particular case, lets double the geometric series and add up each term in the series for $2S(n)$:

Simplifying:

Notice what is in red is actually $S(n)$ except it is missing the first term ($2^0$), lets call this part in red $y$:

where

Substituting in: