\documentclass[twocolumn]{article}

\setlength{\oddsidemargin}{-0.5in}
\setlength{\evensidemargin}{-0.5in}
\setlength{\topmargin}{0.0in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\setlength{\textwidth}{7.0in}
\setlength{\textheight}{9.5in}
\setlength{\parindent}{0in}
\setlength{\parskip}{0.05in}
\setlength{\columnseprule}{0.3pt}
\usepackage{fancyvrb}
\usepackage{relsize}
\usepackage{hyperref}

\begin{document}

Name: \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

Directions: {\bf Work only on this sheet} (on both sides, if needed); do not
turn in any supplementary sheets of paper. There is actually plenty of room
for your answers, as long as you organize yourself BEFORE starting writing.

{\bf Note:  There is an ASCII table on p.37.}

{\bf 1.} Suppose our machine has 5-bit word size, with 2s complement
storge.  

\begin{itemize}

\item [(a)] (10) Using 0s and 1s, show the representations of +5 and -5.

\item [(b)] (20) What are the largest representable positive number and most
negative (i.e. largest in absolute value) negative number?

\item [(c)] (20) Suppose {\bf x} and {\bf y} are declared as {\bf int} on this
machine.  Give an example of positive values of {\bf x} and {\bf y}
for which {\bf x+y} is negative.

\end{itemize}

{\bf 2.}  (10) Consider the code

\begin{Verbatim}[fontsize=\relsize{-2}]
char c = '+';
\end{Verbatim}

Give the hex form of the byte at which {\bf c} is stored.

{\bf 3.}  (20) Consider the code at the top of p.20.  If {\bf I} were read in
as 22, would any element of {\bf X} be affected?  If so, state which
one; if not, state why not.

{\bf 4.}  (20) Consider the code

\begin{Verbatim}[fontsize=\relsize{-2}]
int x;
strncpy(&x,"88",2);
printf("%d\n",x);
\end{Verbatim}

Say this is run on a 16-bit machine.  State what value will be printed out.
Your answer must be in the form of a numerical expression, e.g. $3.45
\times 5^{12} - 13$.

{\bf Solutions:}

{\bf 1.} 00101, 11011; 15, -16; 8+8 is -16, for example

{\bf 2.} 0x2b

{\bf 3.} {\bf X[2]}

{\bf 4.} '8' has ASCIII code 0x38, so the contents of {\bf x} will be
0x3838, and the value printed out will be 
$
3 \times 16^{3} + 
8 \times 16^{2} + 
3 \times 16^{1} + 
8 \times 16^{0}
$.

\end{document}

