[Math] Range two’s complement

binary

The most used formula's to calculate the range of numbers in a two's complement system are + $2^{n-1}-1$ for the highest number and $-2^{n-1}$ for the lowest number.

The problem is that this only works in a binary system. Does the following formula work as well for every system?

+$\frac{R^n}{2}-1$
for the highest number and
-$\frac{R^n}{2}$
for the lowest number.

R = radix (so 2 for binary, 10 for decimal, 16 for hexadecimal)
n = amount of numbers

Best Answer

If you are doing $R$'s complement, to get the negative of a number, change each digit $d$ to $R-1-d$, then add $1$ at the end, you do fine if $R$ is even. If $R$ is odd the divisions by $2$ don't come out even and you can't look at the leading digit to find the sign. For $R=4$, for example, the greatest three digit positive number is $133_4=31_{10}=\frac {4^3}2-1$ and the smallest negative number is $200_4=-32_{10}=-\frac {4^3}2$. For $R=3$ and three digit numbers, you would like the largest positive to be $111_3=13_{10}$ and the smallest negative to be $112_3=-13_{10}$, which fits your equation to within $1$, but you have to look at the whole number to know the sign.