[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Labs] [More Labs] [Assignments] [Quizzes] [Examples] [Book] [Tutorial] [API]

**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).

- S is the sign.
- G is the 1's column.
- F is the 2's column.
- E is the 4's column.
- ...
- H is the 1/2's column.
- I is the 1/4's column.
- J is the 1/8's column.
- ...

- What are the largest and smallest positive values you can represent with this notation?
- How do you represent 0 with this notation?
- How do you negate a number with this notation?

- Suppose x and y use this notation and are both nonnegative. Sketch an algorithm for adding x and y.
- Suppose x and y use this notation and x is larger than y. Sketch an algorithm for subtracting y from x.

Mabel and Marvin Mathemagician have suggested an alternate representation.
They say ``Treat the sixteen digits as 2's complement and then divide by
2^{8} (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?

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

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.

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.

- Created Tuesday, April 6, 1999.
- Updated Friday, Apirl 9, 1999 to make the programming components extra credit.

[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Labs] [More Labs] [Assignments] [Quizzes] [Examples] [Book] [Tutorial] [API]

**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