| CSC 161 | Grinnell College | Spring, 2015 |
| Imperative Problem Solving and Data Structures | ||
This laboratory exercise provides practice with
This lab utilizes a program and a script for processing integer values:
~walker/c/fluency-book/integer-rep.c is written in the C programming language and utilizes fixed-size-storage (both short and long integers)
~walker/scheme/fluency-book/integer-rep is a script that utilizes the Scheme programming language and variable-size-storage.
Your reading described how positive integers are stored within a computer. This part of the lab asks you to apply your understanding from this reading to positive integers, as observed on a computer.
The first several experiments in this lab utilize a program integer-rep. This program is written in the C programming language. In this language (and in most others), integers are stored using a fixed-size-storage approach, as described in the reading.
Copy ~walker/c/fluency-book/integer-rep.c to your account and compile it. Run integer-rep, which initially shows the binary representation of the number 1. Use the operation "A" to add 1 to the values. Then use "A" again, and again, and again. (When starting with the value 1, the integers will become 2, 3, 4, and 5.)
Review the binary representation of each integer, and explain why it has the binary representation printed.
Use the "M" option to set the value to 12. Then use the "M" option 5 times, each time multiplying the values by 2 to obtain 24, 48, 96, 192, and 384. Explain why the binary representation of each integer looks as it does, including how the pattern of 0's and 1's obtained changes as you go from one of these numbers to the next.
Try to use the "I" option to set the integer to a 5-digit positive integer (e.g., 10000), a 10-digit positive integer (e.g., 2000000000), a 15-digit positive integer, and a 20-digit positive integer. Explain what happens in each case.
While integer-rep.c illustrates how integers usually are stored in computers, a few environments utilize the variable-size-storage approach. The Scheme programming language and environment illustrates this alternative approach. With variable-size-storage, the binary representation does not have a 16-bit or 32-bit form; rather, the binary representation uses as many bits as needed. Our experiments will use the script ~walker/scheme/fluency-book/integer-rep
Run ~walker/scheme/fluency-book/integer-rep, written in Scheme. That is, type the following line into a terminal window:
~walker/scheme/fluency-book/integer-rep
This program has much the same interface as the C version you used
above.
Check that the operations for entering integers, addition,
subtraction, multiplication, and division work as they did with the C
version:
Following the same approach as Step 1, determine the binary representations for the positive integers 1, 2, 3, 4, and 5. To what extent are these the same or different from the fixed-size-storage approach?
Repeat Step 3 with this Scheme-based script.
Now that we have some experience with non-negative integers, we look at a few negative numbers.
As in Steps 1-3, use the C program integer-rep.c and the "I" option to set the program's values to -1, -2, -3, and -5. Review the 0's and 1's to determine whether the computer uses sign-magnitude notation, ones complement notation, or twos complement notation. Write a paragraph to justify your conclusion.
Use the "I" option to enter -32766. Then use the "S" option four times to subtract 1 from -32766 . What results do you get with the 16-bit integer form and with the 32-bit integer? Explain why you get each result.
Use the "A" option several times to add 1 to your result of step 8. What can you conclude about the maximum integer that can be stored in 16 bits (assuming the processing is allowed to handle both negative and positive numbers)?
Use a similar approach to find the maximum integer that can be stored in a 32-bit (signed) integer. Explain your result and how you got it.
Read the news account of the computer-related difficulties that grounded all of Comair's flights on December 25, 2004. The article states, the computer system for Comair "has a hard limit of 32,000 changes in a single month." Other articles confirmed that this problem was due to a field in a database that was designed as a 16-bit integer.
What do you think was the real (not rounded) limit for changes to crews at Comair?
From what you know about the fixed-storage-approach for storing integers, identify one or two ways this problem could have been avoided.
Using ~walker/scheme/fluency-book/integer-rep, enter very large negative numbers (e.g., over 20 digits). Explain what happens.
Review your experiments with both the fixed-size-approach and the variable-size-approach for storing integers, and write a paragraph summarizing the observations you have made.
Development of laboratory exercises is an iterative process. Prof. Walker welcomes your feedback! Feel free to talk to him during class or stop by his office.