\documentclass[answers,addpoints,10pt,x11names]{exam}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[most]{tcolorbox}
\usepackage{colortbl}
\usepackage{datetime}
\usepackage{enumerate}
\usepackage{enumitem}
\usepackage{xltxtra}
\usepackage{listings}
\usepackage{listings-mips}

\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{makecell}
\usepackage{multicol}
\usepackage{multirow}

\usepackage{tabularx}
\usepackage{textcomp}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,decorations.pathmorphing,backgrounds,positioning,fit}
\usepackage{pgf-umlcd}
\usepackage{xcolor}

% compact itemized and then enumerated
\setlist{leftmargin=*,
  noitemsep,
  topsep=5pt,
  parsep=0pt,
  partopsep=0pt,
}

\setlist[enumerate]{leftmargin=*,
  itemsep=2pt,
  topsep=0pt,
  parsep=0pt,
  partopsep=0pt,
}


\usepackage{fontspec}
\setmainfont{Gentium Basic}
\setmonofont{Comic Code}[
  Scale          = 0.80,
  UprightFont    = *-Regular,
  ItalicFont     = *-Italic,
  BoldFont       = *-Bold,
  BoldItalicFont = *-Bold Italic
]

\lstset{
  language=[mips]assembler,
  basicstyle=\ttfamily,
}

\DeclareMathOperator{\limplies}{\Rightarrow}
\DeclareMathOperator{\liff}{\iff}
\DeclareMathOperator{\lxor}{\oplus}
\DeclareMathOperator{\qeq}{\overset{?}{=}}
\DeclareMathOperator{\modulus}{\mathbf{mod}}
\DeclareMathOperator{\even}{even}
\DeclareMathOperator{\odd}{odd}
\DeclareMathOperator{\ddiv}{|}
\DeclareMathOperator{\ndiv}{\not|}
\DeclareMathOperator{\contra}{\Rightarrow\mskip-\thinmuskip\Leftarrow}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\Z}{\mathbb{Z}}
\renewcommand{\P}[1]{\mathbb{P}(#1)}

\DeclareMathOperator{\vowel}{vowel}
\DeclareMathOperator{\consonant}{consonant}
\DeclareMathOperator{\isprime}{prime}
\DeclareMathOperator{\equals}{equals}
\DeclareMathOperator{\divides}{divides}

% classname
\newcommand\examNumber{gEncodingIntegers}
\newcommand\semester{Spring 2024}
\newcommand\className{Computer Organization}
\newcommand\classNumber{CIS~356}
\newcommand\classFullName{\classNumber~\className}
\renewcommand{\dateseparator}{-}
\yyyymmdddate

% /classname

\pagestyle{headandfoot}
\firstpageheader{\classFullName\\\semester}{\examNumber\\~}{\today\\~}
\runningheader{\examNumber}{}{\today}


\title{\examNumber}

\newenvironment{showExample}[1]{
  \begingroup
  \renewcommand{\solutiontitle}{\noindent\textbf{Example:}\enspace}
  \printanswers
  \begin{solution}[#1]
  }{
  \end{solution}
  \endgroup
}

\begin{document}

\subsection*{Introduction}
This assignment is a \emph{group} assignment. If I, in the room, do
not \textbf{hear} you interacting with the other students, you are
doing it \emph{wrong}!

\subsection*{Assignment Goals}
\textbf{Learning Outcomes} After completing this group assignment,
each student is expected to be able to
  \begin{itemize}
  \item Convert between \emph{binary}, \emph{decimal}, and
    \emph{hexadecimal} representations of unsigned integers.
  \item Convert between \emph{binary} and \emph{decimal}
    representations of \textbf{signed} integers.
\end{itemize}

\subsection*{Procedure}

\textbf{Get out paper.} The group will turn in \emph{one}
document. Make sure all participating members' names are on the
page.

\noindent
\textbf{Copy each question before the answer.} Since the point is to
make your answer sheet a stand-alone study guide, the copy need not be
verbatim but must give your answer enough context to evaluate.

\noindent
\textbf{Assign Roles.} Students should take roles they
have not held recently (or, perhaps, ever):

\begin{description}
\item[Manager] Move discussion forward.
\item[Recorder] Writes the report that will be turned in.
\item[Reflector] Monitor that everyone gets heard and is caught
  up. (This is a \textbf{group} obligation, really.)
\item[Speaker] (Combine w/ \textbf{Reflector} if necessary.) Asks
  facilitator questions; communicates what the team has done.
\end{description}

\noindent
\textbf{Answer these questions.}

\begin{questions}
\question{}  \textbf{Add} the following binary numbers; indicate whether or not there was
  overflow. The addends are presented in the expected bit width of the sums.
  \begin{parts}
  \part{}
  \begin{tabular}{r}
    \texttt{  1110 1111}\\
    \texttt{+ 0110 0001}\\\hline
    \ifprintanswers
    \textcolor{gray}{\texttt{1 0101 0000}}\\
    \else
    \\
    \fi

  \end{tabular}

  \part{}
  \begin{tabular}{r}
    \texttt{  0001 0010}\\
    \texttt{+ 0110 0110}\\\hline
    \ifprintanswers
    \textcolor{gray}{\texttt{0 0111 1000}}\\
    \else
    \\
    \fi
  \end{tabular}

  \part{}
  \begin{tabular}{r}
    \texttt{  1111 1111}\\
    \texttt{+ 0001 0000}\\\hline
    \ifprintanswers
    \textcolor{gray}{\texttt{1 0000 1111}}\\
    \else
    \\
    \fi
  \end{tabular}
  \end{parts}

\question{} \textbf{Interpret} each problem in question 1 by
  translating the \emph{binary} numbers to corresponding
  \emph{decimal} numbers, assuming they are encoding \emph{unsigned
    integers}. Are the answers the same in both representations?
  \begin{solution}[0.0in]

\begin{lstlisting}
239
 97
 80  336

 18
102
120  120

255
 16
 15  271
\end{lstlisting}
  \end{solution}

\question{} \textbf{Interpret} each problem in question 1 by
  translating the \emph{binary} numbers to corresponding
  \emph{decimal} numbers, assuming they are encoding \emph{sign-magnitude
    integers}. Are the answers the same in both representations?
  \begin{solution}[0.0in]

\begin{lstlisting}
-111
  97
  80  -14

  18
 102
 120  120

  -127
    16
    15  -113
\end{lstlisting}
  \end{solution}

\question{} \textbf{Interpret} each problem in question 1 by
  translating the \emph{binary} numbers to corresponding
  \emph{decimal} numbers, assuming they are encoding \emph{2's-compliment
    integers}. Are the answers the same in both representations?
  \begin{solution}[0.0in]

\begin{lstlisting}
 -17
  97
  80  80

  18
 102
 120  120

  -1
  16
  15  15
\end{lstlisting}
  \end{solution}

\question{} If you were to interpret the integers in question 1 as
  \emph{excess-n} integers, what would \emph{n} be?
  \begin{solution}[0.0in]

    $128 = 2^{8-1}$
  \end{solution}

\question{} \textbf{Convert} each of the following \emph{decimal} numbers into
  their corresponding \emph{6-bit, unsigned, binary number}.
  \begin{multicols}{2}
    \begin{parts}
    \part{} \texttt{32}
    \ifprintanswers
    \textcolor{gray}{\texttt{10 0000}}\\
    \fi
    \part{} \texttt{27}
    \ifprintanswers
    \textcolor{gray}{\texttt{01 1011}}\\
    \fi
    \part{} \texttt{1}
    \ifprintanswers
    \textcolor{gray}{\texttt{00 0001}}\\
    \fi
    \part{} \texttt{15}
    \ifprintanswers
    \textcolor{gray}{\texttt{00 1111}}\\
    \fi
    \end{parts}
  \end{multicols}

\question{} \textbf{Convert} each value in question 6 into a \emph{6-bit,
    signed, 2's-compliment, binary number} or explain why that cannot
  be done.
  \begin{multicols}{2}
    \begin{parts}
    \part{} \texttt{32}
    \ifprintanswers
    Cannot be done: range  is -32 -- 31\\
    \fi
    \part{} \texttt{27}
    \ifprintanswers
    \textcolor{gray}{\texttt{01 1011}}\\
    \fi
    \part{} \texttt{1}
    \ifprintanswers
    \textcolor{gray}{\texttt{00 0001}}\\
    \fi
    \part{} \texttt{15}
    \ifprintanswers
    \textcolor{gray}{\texttt{00 1111}}\\
    \fi
    \end{parts}
  \end{multicols}


\question{} Negate each value in question 6 and \textbf{convert} the result
  into a \emph{6-bit, signed, 2's-compliment, binary number} or
  explain why that cannot be done.
\begin{multicols}{2}
    \begin{parts}
    \part{} \texttt{-32}
    \ifprintanswers
    \textcolor{gray}{\texttt{10 0000}}\\
    \fi
    \part{} \texttt{-27}
    \ifprintanswers
    \textcolor{gray}{\texttt{10 0100}}\\
    \fi
    \part{} \texttt{-1}
    \ifprintanswers
    \textcolor{gray}{\texttt{11 1111}}\\
    \fi
    \part{} \texttt{15}
    \ifprintanswers
    \textcolor{gray}{\texttt{11 0001}}\\
    \fi
    \end{parts}
  \end{multicols}

\question{} Negate each value in question 6 and \textbf{convert} the result
  into a \emph{6-bit, signed, sign-magnitude, binary number} or
  explain why that cannot be done.

  \begin{multicols}{2}
    \begin{parts}
    \part{} \texttt{-32}
      \ifprintanswers
        \textcolor{gray}{\texttt{10 0000}}\\
      \fi
    \part{} \texttt{-27}
    \ifprintanswers
    \textcolor{gray}{\texttt{10 0100}}\\
    \fi
    \part{} \texttt{-1}
    \ifprintanswers
    \textcolor{gray}{\texttt{11 1111}}\\
    \fi
    \part{} \texttt{15}
    \ifprintanswers
    \textcolor{gray}{\texttt{11 0001}}\\
    \fi
    \end{parts}
  \end{multicols}



\question{} Negate each value in question 6 and \textbf{convert} the result
  into a \emph{6-bit, signed, excess-n, binary number} or
  explain why that cannot be done.

\question{} \textbf{Interpret} (into \emph{decimal}) each of the
  following 6-bit patterns as 6-bit numbers according to each of the
  integer encodings we know.

  \begin{tabular}{l|l|l|l|l|}\cline{2-5}
    &Unsigned&Sign/Magnitude&Excess-\emph{n}&2's-Compliment\\\cline{2-5}
    \texttt{10 0000}&&&&\\\cline{2-5}
    \texttt{00 0001}&&&&\\\cline{2-5}
    \texttt{10 0001}&&&&\\\cline{2-5}
    \texttt{11 1111}&&&&\\\cline{2-5}
    \texttt{00 0000}&&&&\\\cline{2-5}
    \texttt{01 1111}&&&&\\\cline{2-5}
    \texttt{11 0000}&&&&\\\cline{2-5}
  \end{tabular}

\question{} Which of the above answers represent the \emph{largest} or
  \emph{smallest} value that can be encoded into a 6-bit
  representation using the given encoding system?
\end{questions}
\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
