Representing $-2.5$ as a floating point number

260 Views Asked by At

I am trying to understand the following:

For example the number $-2.5 = -1*1.25*2^1$ is strored as:
$S = 1$, Exponent $= 1+127 = 128$, Mantissa = $0.25 $

This got me. How do you connect all these numbers to yield $-2.5$ ?

2

There are 2 best solutions below

0
On BEST ANSWER

If you are given a sign bit $S$, 127-offset exponent $e$, and mantissa $m$, you calculate the value as

$$(-1)^S2^{e - 127}(1 + m)$$

So for your values $S=1$, $e=128$, and $m=0.25$,

$$(-1)^1 2^{128-127}(1 + 0.25) = -2.5$$

0
On

Actually, the number $-2.5$ is stored according to the division 32=1+8+23 as

1 | 1000 0000 | 0100 0000 0000 0000 0000 000

according to the bit pattern that you found, i.e., $-2.5=(-1)^1\cdot 2^{128-127}\cdot (1.01)_2$.