Why 8-bit signed binary numbers go from -127 to 128

1.3k Views Asked by At

I'm studying floating point representation using "Numerical Mathematics and Computing 6ed." By Cheney and Kincaid.

This paragraphs, which can be found in page 46, puzzle me:

enter image description here

I know that $m$ is stored in computer's memory roughly as "_ _ _ _ _ _ _ _" where the leftmost slot is reserved for the sign of the number, leaving 7 slots for the number itself. Thus, $11111111_2=-127_{10}$ is the lowest possible value $m$ can attain, while $01111111_2=127_{10}$ is the highest; why, then, the book mentions that $128$ is the highest possible value for $m$?

Thanks in advance.

2

There are 2 best solutions below

3
On BEST ANSWER

This is a convention, but a good one.

In floating point representation that you are studying, $8$ bits are reserved for the exponent $m$, which (obviously) can represent $256$ different values. It makes a lot of sense to pick a contiguous range of exponents, e.g. $0$ to $255$, or $-256$ to $-1$, or $-128$ to $127$, or (what was eventually picked as a standard) $-127$ to $128$.

Now, notice that the exponent will be used to power the number $2$. This means that the actual numbers represented will be in the range of (roughly) $2^{-127}$ to (roughly) $2^{128}$. This is a well-chosen range that can capture very small and also very large numbers. If one of the other, more asymmetric, choices was adopted instead, we would either compromise on not being able to represent very small numbers - or very large numbers.

The fact the chosen range is precisely $-127$ to $128$ probably has something to do with the fact that the mantissa ($q$) represents a number between $(0.1)_2=(0.5)_{10}$ and $1$, so the actual floating point number you eventually get is actually between (roughly) $2^{-128}$ and $2^{128}$, which is as symmetric as you can get!

0
On
  1. Given $n$ bits, you can represent $2^n$ numbers.

  2. $2^n$ will always be even.

  3. If you ignore the bit relating to the sign and only focus on the positive integers, then you’ll get $2^{n-1}$ integers.

  4. Starting from $0$, count back to $2^{n-1}$. This will get you to $2^{n-1}$, but now you don’t have $0$! How can we fix this?

  5. Shift the negative integers over by one to fill in $0$. This will subtract $1$ from the number of negative integers.

  6. An even number minus $1$ is odd.

  7. This gives you an even number of positive integers, but an odd number of negative integers.