Skip to main content

Section 6.2 Digital Representation of Floats

So far we have learned how integers (positive and negative) are stored in the computer’s memory. How about decimal numbers, also known as floats?
In this next video you’ll find out how floats are stored in memory!

Aside: Video Description.

How are real numbers (floats) represented/stored in the computer?
Example: -5,032.4235
Write in scientific notation (decimal):
\begin{equation*} -5.0324235\times 10^3 \end{equation*}
where - is the sign, 5.0324235 is the "mantissa", and 3 is the exponent.
In binary, this representation takes on the following form:
\begin{equation*} -1.mantissa\times 2^{exp} \end{equation*}
where number = sign*1.mantissa*2^exponent
Special cases:
  • Smallest possible exponent --> number = 0
  • Largest possible exponent --> number = NaN (infinity)
Float: range of numbers varies, but ANSI minimum is \(10^{-37}\) to \(10^{37}\)
Double: often 8 bytes
Note: can declare long double --- not necessarily different from double

Check Your Understanding Check Your Understanding

1.

The binary representation of the decimal number 0.75 is 0.11 (which basically stands for \(2^{-1} + 2^{-2} = \frac{1}{2} + \frac{1}{4} = 0.75\)). In scientific notation, this binary number would be written as:
\begin{equation*} 1.1 * 2^{-1} \end{equation*}
Suppose now that 0.75 is stored (in the binary representation) as a float. In this representation, choose the correct option for the following components of the float:
  • sign: (choose from positive / negative / zero)
  • mantissa: (choose from 11 / 1 / -1 / -11)
  • exponent: (choose from 11 / 1 / -1 / -11)