Test 1, CS 3335, Fall 2008

Date: Tuesday, September 30, 2008.

Name (please print): _______________________________________________________________________________

1. Convert the year 1492 to binary and to hex, then convert back to check that your conversion was correct.

2. Take numbers 9 and 11, add and multiply them in binary and in hex.

3. Take numbers 9 and 11, transform that into 2's complement (modulo 1024, to make sure you do not get overflow), compute 9 + (-11), 11 + (-9), and 9 * (-11) in 2's complement, and check the results.

4. Use bitwise exclusive "or" with the code 0xABC to encode the sequence 0x01F, then show how you can decode it.

5. Use the algorithm that we had in class to show how a computer will compute 1/5. It is enough to trace the first two steps.

6. Follow, step-by-step, the standard 2-stage parsing algorithm (with a postfix expression as an intermediate result) for the expression (a+b)/c- c/(a+b); describe the resulting assembler code.

7. For an expression (a+b)/c- c/(a+b), show how the optimizing compiler will assign registers to intermediate results. Take into account that repeating expressions should be only computed once.

8. Explain, based on the need to optimize, why little-endian representations are used in most processors.

9. Explain, based on the need to optimize, why most data types require a power of 2 bytes (2, 4, 8, etc.) to store.

10. Explain, based on the need to optimize, why computers use the same algorithms as we use for addition and multiplication (at least for positive numbers) but use a completely different algorithm for division.