IEEE 754 Single Precision Simulation

written by Teresa Carrigan



Top

WHAT IS IT?

This model demonstrates how the 32-bit IEEE 754 Single Precision representation of a floating point number is interpreted.

Top

HOW IT WORKS

A random 32-digit bit pattern is generated. The first bit tells us the sign. The next eight bits give us the exponent of two. The last 23 bits are the fraction part of the number.

Top

HOW TO USE IT

The setup button generates a random bit pattern.

The special-bit-patterns switch determines the probability that one of the special bit patterns will be generated when you click the setup button. If the switch is on, then about 75% of the time the pattern generated will be interpreted as either zero, infinity, or NaN ("not a number", used when a program tries to divide by zero or take the square root of a negative number, etc.). If the special-bit-patterns switch is off, then almost all of the time the pattern generated will represent a normal number, but there is still a small chance that one of the special patterns will be generated.

The slow-motion slider is an easy way to adjust the speed of the display. Set it to zero if you want to show the final result as quickly as possible. 0.2 is a good setting for most purposes.

The step button does whichever step of the conversion process comes next. It then stops so you can take notes. This is useful when you are first learning the method.

The go button does the entire conversion, at a speed determined by the slow-motion slider. This is useful when you do not need to take notes between each step, or do not wish to press the step button seven times to get an answer.

The show-again button starts the exact problem from the beginning. You may then click either the step button or the go button to see the same demonstration.

Top

THINGS TO NOTICE

Besides the special bit patterns that represent positive and negative infinity, what is the largest number that this format can store? The most negative? The smallest positive number?

When the bit pattern is one of the special ones, we do not have to convert the exponent to decimal.

Top

THINGS TO TRY

Set slow-motion to 0.2, click setup, and then click go.

Set the special-bit-patterns switch to the type of problem you want to drill, then click setup. Attempt one step at a time on paper, and then click the step button to check that you did that step correctly.

Top

EXTENDING THE MODEL

Allow the user to input a starting bit pattern.

Allow the user to input a number in Binary Scientific Notation, and then display the corresponding bit pattern.

Allow the user to input a decimal number, and then display the corresponding bit pattern.

Display the decimal equivalent of the bit pattern.

Top

NETLOGO FEATURES

one-step uses the NetLogo run command combined with a global integer variable step to run the next step, without needing nested ifelse blocks.

handle-special-case uses a similar trick to call the appropriate special case handling procedure, without using ifelse blocks.

Top

CREDITS AND REFERENCES

This model was written by Teresa W. Carrigan, 2004.

Permission to use, modify or redistribute this model is hereby granted, provided that both of the following requirements are followed:

  1. this copyright notice is included.
  2. this model will not be redistributed for profit without permission from Teresa Carrigan.
Contact Teresa Carrigan for appropriate licenses for redistribution for profit.

To refer to this model in academic publications, please use: Carrigan, T. (2004). IEEE 754 Single Precision Simulation model. Blackburn College, Carlinville, IL.

In other publications, please use: Copyright 2004 by Teresa W. Carrigan. All rights reserved.

Top

FOR MORE INFORMATION

For more information on IEEE 754 Single Precision floating point numbers, see one of the following textbooks:
  1. Murdocca, M. and Heuring, V. Principles of Computer Architecture, First Edition, Prentice Hall, pages 45-47
  2. Bronson, G. Java for Engineers and Scientists, First Edition, Thomson/BrooksCole, pages 799-801.
  3. Tanenbaum, A. Structured Computer Organization, Fourth Edition, Prentice Hall, pages 646-650.


Home

Applets on this website were written by Teresa Carrigan in 2004, for use in computer science courses at Blackburn College, with the exception of the Fireworks applet. The applets made with NetLogo require Java 1.4.1 or higher to run. The applets made with NetBeans require Java 1.4.2 or higher to run. Applets might not run on Windows 95 or Mac OS 8 or 9. You may obtain the latest Java plugin from Sun's Java site.