Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 151 additions & 3 deletions chapters/knowledge.tex
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ \section{浮点数}
于是,符号位$S=1$,尾数$M$为$1110\,0000\,0000\,0000\,0000\,000$,阶码$E$为$128_{10}=1000\,0000_2$,则最终的32位单精度浮点数为
$$1\,1000\,0000\,1110\,0000\,0000\,0000\,0000\,000$$

\section{BCD码}
\section{BCD码与二进制码的转换}
\subsection{BCD码简介}
\begin{note}{}{}
本节系摘编。

Expand Down Expand Up @@ -199,7 +200,7 @@ \section{BCD码}
\caption{常见的BCD编码。通常开发使用8421,8421对于新手能一看就懂。}\label{tab3}
\end{table}

\section{BCD码转二进制}\label{sec30}
\subsection{BCD码转二进制}\label{sec30}
BCD码是我们用来表示十进制数的方式,BCD转二进制的算法也就是十进制转二进制的算法。这里我们介绍短除法,该算法是高中课程的内容。

短除法将一个数反复除以2直到商为0,取余数倒序为二进制结果。
Expand Down Expand Up @@ -301,7 +302,7 @@ \section{BCD码转二进制}\label{sec30}
\end{center}
\end{example}

\section{二进制转BCD码}\label{sec31}
\subsection{二进制转BCD码}\label{sec31}
回顾\autoref{exa1}中的算法。每一步中,进行分离最后一位、分组、查表三个操作,最终从第一行的BCD码推到了最后一行的二进制。每一步都是由\autoref{tab5}唯一确定的,所以可以作为一个可靠的算法。反过来想,如果先知道了最后一行的二进制,是否可以反推到第一行的BCD码呢?我们来试试。
\begin{example}{}{}
将二进制1111011转为BCD码。尝试将\autoref{exa2}中的步骤反向。
Expand Down Expand Up @@ -330,3 +331,150 @@ \section{二进制转BCD码}\label{sec31}
\end{tabular}
\end{center}
\end{example}

\section{$\mathbb{Z}_2$上的线性代数}
\subsection{域$\mathbb{Z}_2$简介}
把整数分成奇数和偶数,则有如下运算规律:
\begin{center}
\begin{tabular}{|c|cc|}
\hline
$+$&偶&奇\\\hline
偶&偶&奇\\
奇&奇&偶\\\hline
\end{tabular}
\begin{tabular}{|c|cc|}
\hline
$\times$&偶&奇\\\hline
偶&偶&偶\\
奇&偶&奇\\\hline
\end{tabular}
\end{center}

$\mathbb{Z}_2=\{0,1\}$表示整数除2所得余数的集合,则0代表偶数,1代表奇数,0和1之间的加法和乘法运算遵守上述奇偶的运算规律,即
\begin{center}
\begin{tabular}{|c|cc|}
\hline
$+$&0&1\\\hline
0&0&1\\
1&1&0\\\hline
\end{tabular}
\begin{tabular}{|c|cc|}
\hline
$\times$&0&1\\\hline
0&0&0\\
1&0&1\\\hline
\end{tabular}
\end{center}

另外,定义除法为乘法的逆运算,即$0\div 1=0$、$1\div 1=1$,除数不能为0。定义减法为加法的逆运算,由于$\mathbb{Z}_2$的特殊性,减法和加法的运算规则完全一样。

如果将0和1又看作逻辑中的真和假,则加法对应的是异或,乘法对应的是与,所以可以用$\mathbb{Z}_2$上的运算来描述逻辑。

\subsection{向量与矩阵}
$\mathbb{Z}_2$上的向量即为一组有序的$\mathbb{Z}_2$元素。向量组成向量空间。
\begin{definition}
$\mathbb{Z}_2^n=\{(x_1,\dots,x_n): x_k\in\mathbb{Z}_2\}$是$\mathbb{Z}_2$上的$n$维向量空间。$\mathbb{Z}_2^n$中的元素是$\mathbb{Z}_2$上的$n$维向量。
\end{definition}

向量的加减法定义为对应元素加减:
\[
(x_1,\dots,x_n) + (y_1,\dots,y_n) = (x_1+y_1,\dots,x_n+y_n).
\]

数字乘向量定义为用数字乘向量中的每个元素:
\[
\lambda(x_1,\dots,x_n) = (\lambda x_1,\dots,\lambda x_n).
\]
由于$\mathbb{Z}_2$中仅有0和1两个数字,所以向量的数乘可以列举为
\[
1\mathbf{x}=\mathbf{x},\qquad 0\mathbf{x}=\mathbf{0},
\]
其中粗体小写字母表示向量,$\mathbf{0}$表示零向量,即向量中所有元素都是0。

$\mathbb{Z}_2$元素也可以有序地组成矩阵。矩阵组成矩阵空间。
\begin{definition}
$\mathbb{Z}_2^{m\times n}=\left\{\begin{pmatrix}
x_{11}&x_{12}&\cdots&x_{1n}\\
x_{21}&x_{22}&\cdots&x_{2n}\\
\vdots&\vdots&\ddots&\vdots\\
x_{m1}&x_{m2}&\cdots&x_{mn}
\end{pmatrix}: x_{jk}\in\mathbb{Z}_2\right\}$是$\mathbb{Z}_2$上的$m\times n$维矩阵空间。$\mathbb{Z}_2^{m\times n}$中的元素是$\mathbb{Z}_2$上的$m\times n$维矩阵。
\end{definition}

矩阵也可以看作向量的向量。一个$m\times n$维矩阵既可以理解为由$m$个$n$维行向量组成的列向量也可以理解为由$n$个$m$维列向量组成的行向量。$n$维行向量也可以看作$1\times n$维矩阵,$m$维列向量也可以看作$m\times 1$维矩阵。

按照向量加减法与数乘的定义,矩阵加减法也定义成对应元素加减,矩阵数乘也定义成用数字乘矩阵中的每个元素。

矩阵一般用粗体大写字母表示。零矩阵用$\mathbf{O}$表示。

\subsection{线性组合}
将若干向量用数乘然后相加,得到的结果可以叫做这些向量的\emph{线性组合}。
\begin{definition}
设$\mathbf{x_1},\dots,\mathbf{x_n}\in\mathbb{Z}_2^m$,$\lambda_1,\dots,\lambda_n\in\mathbb{Z}_2$,则$\lambda_1\mathbf{x_1}+\dots+\lambda_n\mathbf{x_n}\in\mathbb{Z}_2^m$是向量$\mathbf{x_1},\dots,\mathbf{x_n}$的一个线性组合。
\end{definition}
将$\mathbf{x_1},\dots,\mathbf{x_n}$排列成矩阵,$\lambda_1,\dots,\lambda_n$排列成向量,则该线性组合可以描述为
\[
(\mathbf{x_1},\cdots,\mathbf{x_n})\begin{pmatrix} \lambda_1 \\ \vdots \\ \lambda_n \end{pmatrix}=\lambda_1\mathbf{x_1}+\dots+\lambda_n\mathbf{x_n}\in\mathbb{Z}_2^m.
\]
其中$\mathbf{x_1},\dots,\mathbf{x_n}$是矩阵中的列向量,$\lambda_1,\dots,\lambda_n$也排列成列向量。以上就是矩阵和列向量相乘的定义。
\begin{definition}
设$\mathbf{A}\in\mathbb{Z}_2^{m\times n}$,$\mathbf{x}\in\mathbb{Z}_2^n$,则$\mathbf{A}\mathbf{x}\in\mathbb{Z}_2^m$定义为
\[
\mathbf{A}\mathbf{x}=\begin{pmatrix}
a_{11}&a_{12}&\cdots&a_{1n}\\
a_{21}&a_{22}&\cdots&a_{2n}\\
\vdots&\vdots&\ddots&\vdots\\
a_{m1}&a_{m2}&\cdots&a_{mn}
\end{pmatrix}
\begin{pmatrix}
x_{1}\\
x_{2}\\
\vdots\\
x_{n}
\end{pmatrix}
=
\begin{pmatrix}
a_{11}x_{1}+a_{12}x_{2}+\cdots+a_{1n}x_{n}\\
a_{21}x_{1}+a_{22}x_{2}+\cdots+a_{2n}x_{n}\\
\vdots\\
a_{m1}x_{1}+a_{m2}x_{2}+\cdots+a_{mn}x_{n}
\end{pmatrix}
\]
\end{definition}

\subsection{解线性方程组}
利用矩阵和列向量的乘法可以描述\emph{线性方程组}。例如方程组
\[
\begin{cases}
a_{11}x_{1}+a_{12}x_{2}+\cdots+a_{1n}x_{n}=b_1\\
a_{21}x_{1}+a_{22}x_{2}+\cdots+a_{2n}x_{n}=b_2\\
\vdots\\
a_{m1}x_{1}+a_{m2}x_{2}+\cdots+a_{mn}x_{n}=b_m
\end{cases}
\]
可以描述为
\[
\underbrace{\begin{pmatrix}
a_{11}&a_{12}&\cdots&a_{1n}\\
a_{21}&a_{22}&\cdots&a_{2n}\\
\vdots&\vdots&\ddots&\vdots\\
a_{m1}&a_{m2}&\cdots&a_{mn}
\end{pmatrix}}_\mathbf{A}
\underbrace{\begin{pmatrix}
x_{1}\\
x_{2}\\
\vdots\\
x_{n}
\end{pmatrix}}_\mathbf{x}
=
\underbrace{\begin{pmatrix}
b_{1}\\
b_{2}\\
\vdots\\
b_{m}
\end{pmatrix}}_\mathbf{b}.
\]

解线性方程组可以用高斯消元法。

\subsection{线性变换与矩阵代数}