This laboratory’s exercises will allow experimenting with the representation of integers and determining what happens when the maximum size of integers is obtained. Download the starter code for this lab integer-rep.tar.gz and extract it with the following commands:
$ mkdir -p csc161/labs/integer-rep
$ cd csc161/labs/integer-rep
$ tar xvzf ~Downloads/integer.tar.gz
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.
Examine the source code of both integer-rep.c and integer-rep.scm. In particular look at the section on Menu Options.
integer-rep.c illustrates how integers usually are stored in computers, while the scheme programming language and enviornment uses a variable-size-storage 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.
The C code you can compile and run in the usual way. The scheme code can be run in a Scheme interpreter by typing the following command into a terminal window:
$ scheme-elk -l integer-rep.scm
Driver: Student closer to the whiteboard
integer-rep.c. When you run it, it 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.Check out this news account of computer related difficulties that grounded all of Comair’s flights on December 25, 2004. The computer system for Comair “has a hard limit of 32,000 charges in a single month.” More recently, there was a similar issue caused by a popular YouTube video.
Use the integer-rep.c program 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 complementnotation.
Next, use the “I” option to set the value to -32766. Then use “S” four times to subtract 1. Explore the results do you get with the 16-bit integer compared to the 32-bit integer.
Use the “A” option several times to add 1 to your result of the previous step. Again, observe what you see in the 16-bit integer compared to the 32-bit integer.
Driver: Student farther from the whiteboard