Assignment 1, due Jun 10

Part of the homework for 22C:60, Summer 2005
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list! All assignments will be due at the start of class on the day indicated, and unless there is what insurance companies call "an act of God" - something outside your control; the only exceptions to this rule will be by advance arrangement.

Remember, summer session goes very quickly! You will fall behind very quickly if you do not keep up with the work.

Each of the following problems (except the first) is worth 1/2 point.

  1. What is your E-mail address? (If you have more than one, give the address you'd prefer used for class purposes.)

    Real Homework!

  2. Background: It is useful to be able to estimate roughly how many decimal digits correspond to a particular power of two. The common rule of thumb is that there are 3 decimal digits for every 10 bits in the number.

    Question: The ratio 3/10 used in the above rule of thumb is an approximation. What is the exact value? Hint: This is a highschool algebra question and the subject is logarithms.

  3. Show the representation of the text "Hello, world?" in 7-bit ASCII, showing your answer as a sequence of 7-bit binary numbers.

  4. Show the representation of the text "Hello, world?" in 7-bit ASCII, showing your answer as a sequence of decimal integers. Hint: Consider doing a binary to decimal conversion on each of the successive values from the previous question.

  5. Consider this sequence of decimal numbers: 72, 97, 119, 107, 101, 121, 101, 115, 33. What 7-bit ASCII text does this represent? Hint: Consider doing a decimal to binary conversion on each of the successive values and then looking them up in the ASCII character set table.

  6. Here is a string of numbers in base 8: 107, 145, 157, 162, 147, 145, 40, 127, 141, 163, 150, 151, 156, 147, 164, 167, 166. What 7-bit ASCII text does this represent? Hint: Consider doing an octal to binary conversion.

  7. Background: The standard for the C language is silent about whether data of type char (usually 8 bits) is to be interpreted as signed or unsigned. As a result, the bit pattern 100000002 could be interpreted as either -128 or +128. If a programmer cares one way or the other, the programmer can use an explicit sign qualifier to indicate which interpretation they intend: For 8-bit numbers, unsigned char allows values from 0 to 255, and signed char allows values from -128 to 127.

    Question: Suppose a program has a value of type char with no explicit sign qualifier, and this value is assigned to two integer variables called i_signed and i_unsigned. Give a two-line code fragment that will fix things up after this assignment so that, no matter which of the possible rules the C compiler uses, these two variables will hold both of the possible interpretations. For example, if the character variable originally held 100000002, i_signed will hold -128 and and i_unsigned will hold 128. Hint: The code is trivial, but it requires an understanding of the fact that signed integer variables in C are represented using two's complement binary.