Instructions: Enter a floating point number in the upper left textfield labeled "number 1:" and a floating point number in the textfield below that is labeled "number 2:". Then select an operation (+,-,/,*) from the bottom button group. The binary representation of the two numbers shows up in the four textfields to the right of each number. Floating point numbers are typically represented in a computer as a sequence of four bytes (doubles are represented by eight bytes). The result of the selected operation shows up in the bottom left textfield labeled "result:". The binary value of the result is shown in the four bytes to its right. Try assigning number 1 the value 23, assigning number 2 the value 34 and multiplying. Any surprises on the binary side?
Floating Point Representation:
The problem with integers is that the highest representable one is
2^{32}-1 which is 4,294,967,295. This is not terribly high.
The solution to representing very large numbers (and very small
numbers too) is to treat each number as though it were written in
scientific notation with a mantissa between 1 and 2 and an exponent.
For example, the number 0.15625 in binary is 0.00101. This is 1.01
(the mantissa) times 2^{-3} (the number -3 which is ...1100
in binary) is called the exponent. The computer representation of
the number 0.15625 as a floating point number uses the rightmost 23
bits to represent the mantissa, the leftmost bit to represent the
sign of the number (0 means positive, 1 means negative) and the
remaining 8 bits to represent the exponent as shown here (stolen
from wikipedia, sorry):
0 00000000 10000000000000000000000 |
The bottom row above shows the result represented as a double (8 bytes). In that case, the exponent is 11 bits and the fraction is 52 bits (with the sign bit this is 64 bits or 8 bytes).