\documentclass[addpoints,12pt]{exam}
\usepackage{datetime}
\usepackage{soul}
\usepackage{tikz}
\usetikzlibrary{arrows,automata,decorations.pathmorphing,backgrounds,positioning,fit}
\usepackage{enumerate}
\usepackage{url}
\usepackage{fontspec}
\newfontfamily\lstlistingfamily[Scale=0.7]{Comic Code}

\usepackage{listings}
\lstset{language=c,
  showstringspaces=false,
  literate={-}{{\texttt{-}}}1{--}{{\texttt{-{}-}}}2{---}{{\texttt{-{}-{}-}}}3,
  basicstyle=\lstlistingfamily
}

% classname
\newcommand\examNumber{Making an Encoder}
\newcommand\semester{Spring 2024n}
\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}
\firstpagefooter{Page \thepage\ of \numpages}
{}
{Points earned: \makebox[.5in]{\hrulefill}\\
  out of a possible \pointsonpage{\thepage} points}
\runningfooter{Page \thepage\ of \numpages}
{}
{Points earned: \makebox[.5in]{\hrulefill}\\
  out of a possible \pointsonpage{\thepage} points}

\pointsinrightmargin

\newcommand{\NOR}{\lstinline{Nor}}
\newcommand{\NAND}{\lstinline{Nand}}
\newcommand{\AND}{\lstinline{And}}
\newcommand{\OR}{\lstinline{Or}}
\newcommand{\XOR}{\lstinline{Xor}}
\newcommand{\NOT}{\lstinline{Not}}
\newcommand{\BIT}{\lstinline{Bit}}
\newcommand{\BYTE}{\lstinline{Byte}}
\newcommand{\REGISTER}{\lstinline{Register}}

\begin{document}
\vspace{0.1in}
\makebox[\textwidth]{Name:\enspace\hrulefill}


For this assignment you may not use any built-in \textbf{decoder},
\textbf{encoder}, \textbf{mux}, or \textbf{demux} components. You may
build and use your own implementations of any of these components
using \AND, \OR, and \NOT.

\begin{questions}
\question{} An \emph{encoder} is a combinatorial circuit that takes
  some number of inputs, say 16, and encodes them as a binary number.

  You are to implement a \lstinline{16To4BitPriorityEncoder} with 16
  inputs and a 4-bit output.

  When \emph{no} inputs are set to 1 (asserted), then the output
  should be a binary 0. When just input $i$ is asserted, the output is
  the binary representation of $i$.

  The \emph{priority} part is what happens if more than one wire is
  asserted simultaneously: the output is the binary encoding of the
  \emph{highest} asserted wire.

  The circuit has 16 1-bit inputs and 1 4-bit output. Label the inputs
  as \lstinline|i0| through \lstinline|iF| (0123456789ABCDEF) and the
  output \lstinline|out|.

  Write a \emph{complete} test case for your encoder for all inputs with only
  one wire asserted. Also test every wire simultaneously with \lstinline{i0} and
  simultaneously with \lstinline{iA}.

  Save your correct \lstinline|16To4BitPriorityEncoder.dig| file.

\question{} A \emph{decoder} is the opposite of an encoder: given
  $\log_2 n$ inputs, interpret that as a binary number and assert one
  of $n$ wires. You are to implement a \lstinline{4BitToOneOf16Decoder}.

  The circuit has a 4-bit binary input (\lstinline{i}) and sixteen
  1-bit outputs (\lstinline{out0, out1, ..., outF}).

  Write a \emph{complete} test case for your encoder for all
  possible input values.

  Save your correct \lstinline|4BitToOneOf16Decoder.dig| file.
\end{questions}

\textbf{Deliverables:} When all the tests pass, upload a
\lstinline{git} repository to Gitea with your two files. No need for a
\lstinline{README} for this assignment.
\end{document}

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