Skip to main content
Source Link

There is an age-old adage:

If you give a person a fish, you feed that person for one day.
If you teach a person to fish, you feed that person for a life-time.


I will tell you how to find the IEEE single-precision floating point number for some decimal numbers.

Let us begin with scientific notation.

Usually, scientists prefer seeing option 1 over option 2, where options 1 and 2 are both shown below:

  1. \$5.6 * 10^{7}\$
  2. \$0.0056 * 10^{4}\$

If you write numbers in scientific notation, you are not supposed to write \$0.0056 * 10^{4}\$. You are supposed to slide all of the numbers to the left or to the right until there is exactly one non-zero digit to the left of the decimal point.

The decimal expansions of both mathematical expressions are the same, but \$0.0056\$ has too many zeros to the left of the decimal-point.

You can write \$0.5\$ as \$5.0 * 10^{-1}\$.

Note that a normalized IEEE float can be thought of as:

\$(\mathtt{SIGN\_BIT}) * (\mathtt{FRACTION}) * 2^{(\mathtt{EXPONENT})} \$

So, we could have:

\$0.5 = \underbrace{(+1)}_{\mathtt{SIGN\_BIT}} * \underbrace{(5.0)}_{\mathtt{FRACTION}} * \underbrace{(10^{-1})}_{\mathtt{EXPONENT}}\$

  1. The \$\mathtt{SIGN\_BIT}\$ is either \$(+1)\$ or \$(-1)\$.
  2. The \$\mathtt{BASE}\$ will be stored inside of \$23\$ bits.
  3. The \$\mathtt{POWER}\$, also known as the \$\mathtt{EXPONENT}\$, fits inside of \$8\$ bits.

One single bit is like one single single square on a sheet of graph paper.

Note that:

  1. \$0.5 = \dfrac{1}{2}\$

  2. \$\dfrac{1}{2}\$ becomes $2^{-1}$

  3. \$2^{-1}\$ becomes \$1*2^{-1}\$

Notice that there is a non-zero digit to the left of the decimal point in 0.5 * 10^{0}. slide the 5 in 0.5* 10^{0} to the left to get \$5.0 * 10^{-1}\$

The mathematical expression \$1*2^{-1}\$ looks almost like scientific-notation, except that we use a two instead of a ten.

To summarize:

\$0.5 = \begin{pmatrix}\dfrac{1}{2}\end{pmatrix} = 2^{-1}\$

Now, we can do that in base 2 instead of base 10.

\$(0.1 * 10^{-1})_{2}\$ has a zero on the left of the binary-point.

\$(1.0 * 10^{-2})_{2}\$ has a $1$ to the left of the binary-point.

The people who wrote the IEEE standards assumed that \$\mathtt{BASE}\$ would always start with a \$1\$. Those people preferred option 1 over option 2 where options 1 and 2 are shown below.

  1. \$one \quad dot \quad something \quad something\$
  2. \$zero \quad dot \quad something \quad something\$

As such you should slide things around until you have (one - point - something) times \$2\$ raised to some power.

We never bother to record the \$1\$ to the left of the binary-point.

We are not allowed to have zero-dot-something.

If the number is always one-dot-something, then why bother recording the one?

For recording \$0.5\$ we record \$(0.0 * 10^{-2})_{2}\$ instead of recording \$(0.0 * 10^{-2})_{2}\$.

When converting from the numbers people write on paper with pencils into IEEE format, delete the leftmost \$1\$ from the base.

Thus, \$(1.100101)_{2}*(10)_{2}^{(1010)_{2}}\$ is stored as \$(0.100101)_{2}*(10)_{2}^{(1010)_{2}}\$ because we delete the leftmost \$1\$ in the base of a normalized floating point number.

Note that the \$\mathtt{BASE}\$ is never allowed to be equal to the number zero.

So we want something like the following for 0.5:

\$(\mathtt{SIGN\_BIT}) * (\mathtt{BASE}) * (\mathtt{POWER}) \$

\$\underbrace{(+1)}_{ \mathtt{SIGN\_BIT}} * \underbrace{(1)}_{\mathtt{BASE}} * \underbrace{(2^{-1})}_{\mathtt{POWER} }\$

This answer could use some heavy revision.
Feel free to edit what I have written.

Post Made Community Wiki by Samuel Muldoon