Fundamentals of Computer Science II (CSC-152 99S)


Assignment 8: Fixed Precision Binary

Assigned: Tuesday, April 6, 1999
Due: Wednesday, April 14, 1999

In this assignment, you will apply your understanding of binary representation, numerical computation, and related issues to the problem of fixed-precision binary numbers.

Assume that we're using a sixteen-bit fixed-precision binary representation. The leftmost bit is the sign bit. The rightmost eight bits fall after the decimal point. The other seven bits fall to the left of the decimal point. The number therefore has the form SABCDEFG.HIJKLMNO (although without an explicit decimal point).

Problems

1. Thought questions

2. Algorithms

3. An alternate representation

Mabel and Marvin Mathemagician have suggested an alternate representation. They say ``Treat the sixteen digits as 2's complement and then divide by 28 (256)''. In their representation, 0000000010000000 is 128/256 or 0.5. Similarly, 0000001100000000 is 3.

How might we write -5? We start with 5 in standard binary notation: 101. We multiply by 256 to accomodate the division required for interpretation: 10100000000. We add the leading 0's: 0000010100000000. We invert the digits: 1111101011111111. Finally, we add 1: 1111101100000000.

a. How might you write 9.125 in the Mathemagicians' representation?

b. How might your write -9.125 in the Mathemagicians' representation?

c. How might you add two numbers that use this notation?

d. How might you subtract two numbers that use this notation?

4. Comparision

What are the advantages and disadvantages of the Mathemagicians' representation as compared to our earlier fixed-point representation?

Extra Credit

A. From ``binary'' to float

Write a method that takes a string of sixteen 0's and 1's as a paramter and returns the value of that sequence if it is interpreted using this notation.

For example, if the input to your method is 1000000010000000, the output should be -0.5. Similarly, if the input to your program is 0000010101000000, the output should be 5.25.

Make sure to create an appropriate accompanying test program.

B. From float to ``binary''

Write a method that takes a float as a parameter and returns a string that corresponds to the approximate representation of that float using this notation.

Make sure to create an appropriate accompanying test program.

History


Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS152/99S/Assignments/assign.08.html

Source text last modified Fri Apr 9 10:31:57 1999.

This page generated on Fri Apr 9 10:38:02 1999 by SiteWeaver. Validate this page's HTML.

Contact our webmaster at rebelsky@math.grin.edu