Skip to main content
Logo image

Section 6.1 Digital Representation of Floats

Recall the funny division behavior we notice in the C programming language when using integers. Feel free to play around in this code window to refresh your memory and experiment in order to analyze this behavior.

admin.....open in new window

Check Your Understanding Check Your Understanding

1.

Here is a quick review question: Using integer arithmetic, what is the result of 15/4?
  • Correct!
  • Not quite - try again!
  • 3.75
  • Not quite - try again!
  • 0.75
  • Not quite - try again!
Hint.
In an integer division only the integer part of the result is accounted for.

2.

Another quick review question: In the C programming language, what is the result of 19/2.0?
  • 9.5
  • Correct!
  • Not quite - try again!
  • 10
  • Not quite - try again!
  • 9R1
  • Not quite - try again!
Hint.
By writing 2.0 instead of 2 in the computation, the data type in which the operation is performed is automatically cast to a floating point which means that the result can also be a floating point number.

3.

And another review question: Suppose that a and b are variables of type int, a has the value 8, b has the value 6. In the C programming language, what is the value of (a+b)/3?
  • Correct!
  • Not quite - try again!
  • 4.6
  • Not quite - try again!
  • 4.67
  • Not quite - try again!
Hint.
Because of the data types of a and b, an integer division is performed here.
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!
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)