How to represent the decimal value $- 7.5$ as a floating point number?

1k Views Asked by At

Consider the following $32$-bit floating-point representation scheme as shown in the format below :

A $1$ bit sign field

A $24$ bit fraction field

and a $7$ bit exponent field (in excess-$64$ signed integer representation, with 16 being the base of exponentiation)


How to represent the decimal value $-7.5$ as a normalized floating point number in the given format?


I am not getting why this question assumes $16$ being the base of exponentiation, as I have always assumed base $2$?

2

There are 2 best solutions below

2
On BEST ANSWER

I believe your question is:

I am not getting why is this question assumes $16$ being the base of exponentiation as I have always did by assuming base $2$?

Presumably it's as an exercise to see if you understand the principles behind floating point numbers rather than having just learnt a set of steps. The task is asking about a format which differs from IEEE single precision in two ways:

  • The exponent is in base 16 (rather than IEEE's 2);
  • the fraction field is 24 bits long (rather than IEEE's explicit 23 with an implied first bit being 1).

Since the question is not using a standard floating-point format anyway (because of point 2), why assume it would be standard in respect of point 1?

0
On

As @PatrickStevens points out, this problem is meant to make you think about the basic ideas involved in floating point representation and explore some of the design trade-offs.

To find the representation of $-7.5$ in IEEE 754 single-precision format, you'd write it as $(-1)^1 \cdot 1.875 \cdot 2^{129-127}$.

The exponent $1$ is the sign bit, $1.875$ is a number in the required $1.f$ form, and $129$ is the excess-$127$ exponent. You'd then take $0.875$ and turn it into a $23$-bit binary number, convert $129$ to an $8$-bit binary number and put everything together to form a $32$-bit floating point number.

For your problem the steps are similar, obviously with a different base ($16$) and bias ($64$) for the exponent. The one interesting question you want to ask yourself before you get into the details is, can I still use the hidden-bit trick? That is, can I always write my number as $(-1)^s \cdot 1.f \cdot 16^\text{some integer}$?