Program 2

(printable version)

The purpose of this second SAL programming assignment is:

Program Statement

Write a SAL program that reads a simplified form of a base ten floating point number and prints a simple version of its internal IEEE representation. Assume that the input number consists of from 1 to 6 decimal digits, followed by a decimal point, followed by from 1 to 6 more decimal digits, terminated by '\n'. All other input should be reported as "bad input." Use getc to read the characters in the number. Build the number and store its value in a .float type variable. Your program should print out the internal representation of the number in the form:

1.bbb bbbb bbbb bbbb bbbb bbbb * 2^e

where the leading 1 is the hidden bit in the IEEE representation and the b's are the 23 bits in the significand. The e is the biased-127 value of the exponent.

NOTE 1: We have simplified the "standard" definition of a floating point number to make this programming assignment somewhat easier. Using our definition, the following are not legal base 10 floating point numbers: +2.1, -54.06 (can't have a sign), 70., .003 (need a digit before and after the ".").

NOTE 2: The little e is a base 10 integer and its value can be positive or negative. If it is negative, -5 for example, write the 2^e part as 2^-5.

Sample Runs

Bold indicates user input, italics indicate annotation, everything else would be printed by your program.

input a special float: 2.25
answer is: 1.001 0000 0000 0000 0000 0000 * 2^1
all done

or

input a special float: 134.0625
answer is: 1.000 0110 0001 0000 0000 0000 * 2^7
all done

or

input a special float: 0.1234
answer is: 1.111 1100 1011 1001 0010 0100 * 2^-4
all done

or

input a special float: +134.0625 <- can't use a '+' sign
bad input
all done

or

input a special float: 1234567.0625 <- too many digits before '.'
bad input
all done

or

input a special float: .0625 <- need at least one digit before '.'
bad input
all done

or

input a special float: a#$,*123 <- bad characters
bad input
all done

Requirements

Hints

Handing in your program

You must "hand in" your program (the SAL source code) to the computer directly by

cp p2.s ~cs354-1/handin/username/P2/.

just once, where "p2.s" is the name of the file containing your SAL source code. No printouts will be turned in. I will run your program several times using different test data.

Solution