Giancarlo Rinaldo added file bits3.tex  about 8 years ago

Commit id: 92bb82ffb992ffcadeac55b8110e2a9deb06d575

deletions | additions      

         

\section{Vectors of Bits}\label{Sec:Vectors}  With only one bit we cannot do so much. In general the computer deals with   sequences of bits, that are ``ordered set'', called {\em vectors}, commonly   defined {\em arrays} or {\em strings} in Computer Science. Known vectors of bits are: nibbles that   are (vectors of $4$ bits); bytes vectors of $8$ bits and so on. In general we   call \emph{stream} a vector whose exact size is not known \emph{a priori}.  We will usually visualize them as blocks of one-bit bricks:  \begin{center}  \begin{tabular}{ |c | c | c | c | c | c |}  \hline  0 & 1 & 0 & 1 & 0 & 1 \\  \hline  \end{tabular}  \end{center}  From now on we use the standard notation that represents a vector between ``('' and ``)'' and numbers separated by ``,''. That is  \begin{center}  \begin{tabular}{ |c | c | c | }  \hline  0 & 1 & 1\\  \hline  \end{tabular}  \end{center}  is $(0,1,1)$.  The operations on $\Fb$-vectors can be extended componentwise, that is if we   sum two vectors bit by bit with respect to the position we have:  \begin{equation}\label{eq:vec}  (0,1,1)+(1,0,1)=(1,1,0).   \end{equation}  \begin{Exercise}\label{VettoreOpposto}  Every vectors has an opposite with respect to the sum. Are you able to find it?   \end{Exercise}  \begin{Exercise}\label{AndOrNotNice}  $\AND$ and $\OR$ considered as operations on bits are not nice as the sum (that is XOR). Why?   \end{Exercise}  We can also extend componentwise the idea of \emph{multiple}: the multiple of a   vector $b$ with respect to an integer $a$ is obtained by multiplying by $a$   each component of $b$. Here is an example  \[  3\cdot (1,0,1)=(3\cdot 1, 3\cdot 0,3 \cdot 1)=(1,0,1).   \]  \begin{Exercise}\label{MultiploVett}  Compute $5 \cdot (1,1,0)$ and $6 \cdot (0,1,0)$.  \\  Can you derive a rule to compute the multiple of a vector? (see exercise   \ref{MaxiSum}).   \end{Exercise}  Another structure useful to manage ordered sets, like vectors, is the set of   polynomials described in section \ref{Sec:Polynomials}.   We recall that the sum of two polynomials, $x+1, x^2+1 \in \Fb$, is %that is $$(x+1) + (x^2+1)= x^2 + x+(1+1).$$ Since in $\Fb$ $1+1=0$, we finally get   \begin{equation}\label{eq:pol}  (x+1) + (x^2+1)= x^2+x.   \end{equation}  \begin{Exercise}\label{Vectors2Poly}  Do you see any connections between \ref{eq:vec} and \ref{eq:pol}?  \end{Exercise}  As you have seen in the previouse exercise nice and meaningful operations on vectors can be interpreted through operations on polynomials. In the rest of the section we give other examples.   One of the most important and fast operations in a CPU is shifting to the left or to the right of one position a vectors of bits (register). For example shifting to the   right (or to the left) we have:  \begin{equation}\label{shift}  (1,1,0,1,0) {\Longleftrightarrow} (0,1,1,0,1).   \end{equation}  The polynomials associate to (\ref{shift}) are  \begin{equation}\label{shiftpol}  x^4+x^3+x {\Longleftrightarrow} x^3+x^2+1.   \end{equation}  That is shifting to the left a vectors corresponds to multiply the polynomial by $x$ and shifting to   the right is dividing the polynomial by $x$ itself.  \begin{Exercise}  Suppose you want to make a copy of a vectors of $n$ bits. For example let $n=3$   and we want that $(1,0,1)$ becomes $(1,0,1,1,0,1)$. Using the polynomial   notation for the vector and multiplying by a new polyomial $p(x)$ you can obtain   the result expected. Who is $p(x)$?  \end{Exercise}  Another example that is of big interest is the following. Suppose that the fourth bit (the one with ``?'' symbol) in a vector $x$  \[  x=(?,1,1,0)  \]  is computed by the sum of the first and the third. In languages as ``C'' we can say  \[  x[3]=x[2]+x[0]  \]  where $x[0]$ represents the first entry of the vector and $x[2]$ the third one. In a polynomial notation this ``function'' becomes  \[  x^3=x^2+x^0  \]  where that is the exponents represent the positions of the entries of the vector.  We can also define a product operation between vectors of bits, by multiplying   bits in the same position and summing the resulting products:  $$(0,1,1)\cdot(1,0,1)= 0 \cdot 1 +1 \cdot 0 + 1 \cdot 1 =1.$$  \begin{Exercise}  Compute as vector the product $(x^n+1)h(x)$ and $(x^+1)^n h(x)$ and give your   comments.  \end{Exercise}