This commit is contained in:
许大仙 2024-08-23 16:12:58 +08:00
parent 8c9894d099
commit 31069c8963
69 changed files with 143 additions and 56 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 209 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 819 KiB

View File

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 778 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 126 KiB

After

Width:  |  Height:  |  Size: 778 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

View File

Before

Width:  |  Height:  |  Size: 794 KiB

After

Width:  |  Height:  |  Size: 794 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 240 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 363 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 237 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 487 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 238 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 489 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 287 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 287 KiB

View File

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 190 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 444 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 193 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 98 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 461 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 533 KiB

View File

Before

Width:  |  Height:  |  Size: 9.7 KiB

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 962 KiB

After

Width:  |  Height:  |  Size: 156 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 533 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

View File

Before

Width:  |  Height:  |  Size: 82 KiB

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 962 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

Before

Width:  |  Height:  |  Size: 6.6 MiB

After

Width:  |  Height:  |  Size: 6.6 MiB

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

View File

Before

Width:  |  Height:  |  Size: 220 KiB

After

Width:  |  Height:  |  Size: 220 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 225 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 348 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 195 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 819 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 400 KiB

View File

@ -599,7 +599,7 @@ int main() {
* 在生活中,如果一个容器的容量是固定的,我们不停的向其中注入水,那么当容器中充满水之后,继续注入,就会溢出,如下所示:
![](./assets/0.jpg)
![](./assets/3.jpg)
* 在程序中也是一样的各种整数类型在内存中占用的存储单元是不同的short 在内存中占用 2 个字节的存储单元int 在内存中占用 4 个字节的存储单元。这也就意味着,各种整数类型只能存储有限的数值,当数值过大或多小的时候,超出的部分就会被直接截掉,那么数值就不能正确的存储,我们就将这种现象就称为`溢出`overflow
* 如果达到了最大值,再进行加法计算,数据就会超过该类型能够表示的最大值,叫做`上溢出`。
@ -615,7 +615,7 @@ int main() {
* 以 `unsigned char` 类型为例,它在内存中占用的存储单元是 1 个字节,即 8 位。如果所有位都设置为 `0` ,它的最小值就是 `0` ;如果所有位设置为 `1` ,它的最大值就是 `2⁸ - 1 = 255` ,如下所示:
![](./assets/无符号的取值范围1.drawio.svg)
![](./assets/4.svg)
* 那么,`unsigned char` 的最大值是如何计算出来的?最简单的方法就是这样的,如下所示:
@ -643,7 +643,7 @@ $S_n = a_1 \times \frac{1 - r^n}{1 - r}$
* 其对应的换算过程,如下所示:
![](./assets/无符号的取值范围2.drawio.svg)
![](./assets/5.svg)
> [!IMPORTANT]
>
@ -703,8 +703,8 @@ $S_n = a_1 \times \frac{1 - r^n}{1 - r}$
> [!IMPORTANT]
>
> * ① 通过这种方式,`-128` 就成为了补码的最小值 `1000 0000`,而这个值不会与其他任何正数或负数的补码冲突。
> * 如果采用原码存储,那么将会出现 `+0``-0` 的情况,即:`0000 0000`、`1000 0000`,这样在取值范围就存在两个相同的值,多此一举。
> * 如果采用原码存储,最大值不变是 `127` ,但是最小值只能存储到 `-127` ,因为 `-128` 的原码是 `1000 0000``-0` 的原码冲突。
> * 如果采用`原码`存储,那么将会出现 `+0``-0` 的情况,即:`0000 0000`、`1000 0000`,这样在取值范围内,就存在两个相同的值,多此一举。
> * 如果采用`原码`存储,最大值不变是 `127` ,但是最小值只能存储到 `-127` 不能存储到 `-128`因为 `-128` 的原码是 `1000 0000``-0` 的原码冲突。
> * ② 这就是补码系统的强大之处,它能让整数的范围连贯,并且实现了加法和减法的统一处理。
> * ③ 按照上述的方法,我们可以很容易得计算出:
> * `char`1 个字节) 的取值范围是:`[-2⁸, 2⁸ - 1]`。
@ -714,33 +714,40 @@ $S_n = a_1 \times \frac{1 - r^n}{1 - r}$
### 1.3.4 数值溢出
* 对于无符号的数值溢出:
* 对于`无符号`的数值溢出:
* 当数据到达最大值的时候,再 `+1` 就会回到无符号数的最小值。
* 当数据达到最小值的时候,再 `-1` 就会回到无符号数的最大值。
* 那么,无符号的上溢出,原理就是这样的:
> [!IMPORTANT]
>
> * ① 对于无符号整数的运算,如:加、减、乘、除、取余等,其最小值是 0 ,最大值是 `2^n - 1` 。如果某个计算结果超出了这个范围,计算机会自动将结果对 `2^N` 取余(模),从而丢失高位,只保留低位。
> * ② 以 `8` 位无符号整数而言,最大值是 `255`1111 1111那么 `255 + 1` 的结果就是 `(2^8 -1 + 1) % 2^8 = 0`,商是 `256`
> * ③ 以 `8` 位无符号整数而言,最小值是 `0`0000 0000那么 `0 - 1` 的结果就是 `(0 - 1) % 2^8 = 255`,商是 `-1`
![](./assets/3.png)
* 那么,`无符号`的`上溢出`,原理就是这样的:
* 那么,无符号的下溢出,原理就是这样的(需要先借位,然后再减):
![](./assets/6.svg)
![](./assets/4.png)
* 那么,`无符号`的`下溢出`,原理就是这样的:
* 对于有符号的数值溢出:
![](./assets/7.svg)
* 对于`有符号`的数值溢出:
* 当数据到达最大值的时候,再 `+1` 就会回到有符号数的最小值。
* 当数据达到最小值的时候,再 `-1` 就会回到有符号数的最大值。
* 那么,有符号的上溢出,原理就是这样的:
* 那么,`有符号``上溢出`,原理就是这样的:
![](./assets/5.png)
![](./assets/8.svg)
* 那么,有符号的下溢出,原理就是这样的:
* 那么,`有符号``下溢出`,原理就是这样的:
![](./assets/6.png)
![](./assets/9.svg)
> [!NOTE]
> [!IMPORTANT]
>
> 在实际开发中,选择合适的数据类型,以避免数值溢出问题!!!
> * ① 在实际开发中,选择合适的数据类型,以避免数值溢出问题!!!
> * ② 数据溢出错误会导致软件运算结果出错1996 年的亚利安5号运载火箭爆炸、2004 年的 Comair 航空公司航班停飞事故。
@ -789,11 +796,11 @@ int main() {
* 在生活中,我们除了使用`整数`18、25 之外,还会使用到`小数`3.1415926、6.18 等,`小数`在计算机中也被称为`浮点数`(和底层存储有关)。
* `整数`在计算机底层的存储被称为`定点存储`,如下所示:
![](./assets/7.png)
![](./assets/10.svg)
* `小数`在计算机底层的存储被称为`浮点存储`,如下所示:
![](./assets/8.png)
![](./assets/11.svg)
> [!NOTE]
>
@ -1068,12 +1075,12 @@ int main() {
* 在 C 语言中char 本质上就是一个整数,是 ASCII 码中对应的数字,占用的内存大小是 1 个字节(存储空间),所以 char 类型也可以进行数学运算。
![](./assets/9.png)
![](./assets/12.png)
* char 类型同样分为 signed char无符号和 unsigned char有符号其中 signed char 取值范围 -128 ~ 127unsigned char 取值范围 0 ~ 255默认是否带符号取决于当前运行环境。
* `字符类型的数据`在计算机中`存储`和`读取`的过程,如下所示:
![](./assets/10.png)
![](./assets/13.png)
@ -1270,7 +1277,7 @@ int main() {
* 不同类型的数据进行混合运算的时候,会发生数据类型转换,`窄类型会自动转换为宽类型`,这样就不会造成精度损失。
![](./assets/11.png)
![](./assets/14.png)
* 转换规则:
* ① 不同类型的整数进行运算的时候,窄类型整数会自动转换为宽类型整数。
@ -1278,7 +1285,7 @@ int main() {
* ③ 整数和浮点数进行运算的时候,整数会自动转换为浮点数。
* 转换方向:
![](./assets/12.png)
![](./assets/15.png)
> [!WARNING]
>
@ -1384,7 +1391,7 @@ int main() {
* 在赋值运算中,赋值号两边量的数据类型不同时,等号右边的类型将转换为左边的类型。
* 如果窄类型赋值给宽类型,不会造成精度损失;如果宽类型赋值给窄类型,会造成精度损失。
![](./assets/14.png)
![](./assets/16.png)
> [!WARNING]
>
@ -1458,7 +1465,7 @@ int main(){
>
> 这些存储单元中,存储的都是 0 和 1 这样的数据,因为计算机只能识别二进制数。
![](./assets/15.svg)
![](./assets/17.svg)
* 并且,为了方便管理,每个独立的小单元格,即:存储单元,都有自己唯一的编号(内存地址),如下所示:
@ -1466,7 +1473,7 @@ int main(){
>
> 之所以,要给每个存储单元加上内存地址,就是为了`加快`数据的`存取速度`,可以类比生活中的`字典`以及`快递单号`。
![](./assets/16.svg)
![](./assets/18.svg)
* 我们在定义变量的时候,是这么定义的,如下所示:
@ -1496,7 +1503,7 @@ int num = 10;
> * ② 在实际开发中,我们通常将普通变量等价于内存中某个区域的值(底层到底是怎么转换的,那是编译器帮我们完成的,我们通常无需关心,也没必要关心)。
> * ③ 某些动态的编程语言JavaScript ,在定义变量的时候,是不需要给出数据类型的,编译器会根据赋值情况自动推断出变量的数据类型,貌似很智能;但是,这无疑增加了编译器的工作,降低了程序的性能(动态一时爽,重构火葬场,说的就是动态编程语言,不适合大型项目的开发;所以,之后微软推出了 TypeScript ,就是为了给 JavaScript 增加强类型系统,以提高开发和运行效率)。
![](./assets/17.svg)
![](./assets/19.svg)
@ -1511,11 +1518,11 @@ int num = 10;
* 运算符是一种特殊的符号,用于数据的运算、赋值和比较等。
* `表达式`指的是一组运算数、运算符的组合,表达式`一定具有值`,一个变量或一个常量可以是表达式,变量、常量和运算符也可以组成表达式,如:
![](./assets/18.png)
![](./assets/20.svg)
* `操作数`指的是`参与运算`的`值`或者`对象`,如:
![](./assets/19.png)
![](./assets/21.svg)
* 根据`操作数`的`个数`,可以将运算符分为:
* 一元运算符(一目运算符)。
@ -1977,13 +1984,13 @@ int main() {
* 示例:`9 & 7 = 1`
![](./assets/20.png)
![](./assets/22.svg)
* 示例:`-9 & 7 = 7`
![](./assets/21.png)
![](./assets/23.svg)
### 2.6.4 按位或
@ -1997,13 +2004,13 @@ int main() {
* 示例:`9 | 7 = 15`
![](./assets/22.png)
![](./assets/24.svg)
* 示例:`-9 | 7 = -9`
![](./assets/23.png)
![](./assets/25.svg)
### 2.6.5 按位异或
@ -2026,13 +2033,13 @@ int main() {
* 示例:`9 ^ 7 = 14`
![](./assets/24.png)
![](./assets/26.svg)
* 示例:`-9 ^ 7 = -16`
![](./assets/25.png)
![](./assets/27.svg)
### 2.6.6 按位取反
@ -2044,13 +2051,13 @@ int main() {
* 示例:`~9 = -10`
![](./assets/26.png)
![](./assets/28.svg)
* 示例:`~-9 = 8`
![](./assets/27.png)
![](./assets/29.svg)
### 2.6.7 二进制左移
@ -2060,13 +2067,13 @@ int main() {
* 示例:`3 << 4 = 48` 3 × 2^4
![](./assets/28.png)
![](./assets/30.svg)
* 示例:`-3 << 4 = -48` -3 × 2 ^4
![](./assets/29.png)
![](./assets/31.svg)
### 2.6.8 二进制右移
@ -2081,13 +2088,13 @@ int main() {
* 示例:`69 >> 4 = 4` 69 ÷ 2^4
![](./assets/30.png)
![](./assets/32.svg)
* 示例:`-69 >> 4 = -5` -69 ÷ 2^4
![](./assets/31.png)
![](./assets/33.svg)
## 2.7 三元运算符
@ -2200,17 +2207,17 @@ int main() {
* `字符集`和`字符集编码`之间的关系如下:
![](./assets/32.png)
![](./assets/35.png)
* Linux 中安装帮助手册:
![](./assets/33.gif)
![](./assets/36.gif)
### 3.3.2 ASCII 编码
* 从`冯·诺依曼`体系结构中,我们知道,计算机中所有的`数据`和`指令`都是以`二进制`的形式表示的;所以,计算机中对于文本数据的数据也是以二进制来存储的,那么对应的流程如下:
![](./assets/34.png)
![](./assets/37.png)
* 我们知道,计算机是上个世纪 60 年代在美国研制成功的,为了实现字符和二进制的转换,美国就制定了一套字符编码,即英语字符和二进制位之间的关系,即 ASCII American Standard Code for Information Interchange编码
- ASCII 编码只包括了英文字符、数字和一些特殊字符,一共 128 个字符,并且每个字符都分配了唯一的数字,范围是 0 - 127。
@ -2227,24 +2234,24 @@ int main() {
man ascii
```
![](./assets/35.gif)
![](./assets/38.gif)
* 其对应的 ASCII 编码表,如下所示:
![](./assets/36.gif)
![](./assets/39.gif)
* 但是,随着计算机的发展,计算机开始了东征之路,由美国传播到东方:
![](./assets/37.png)
![](./assets/40.png)
- 先是传播到了欧洲,欧洲在兼容 ASCII 编码的基础上,推出了 ISO8859-1 编码,即:
- ISO8859-1 编码包括基本的拉丁字母表、数字、标点符号,以及西欧语言中特有的一些字符,如:法语中的 `è`、德语中的 `ü` 等。
- ISO 8859-1 为每个字符分配一个单字节8 位)编码,意味着它可以表示最多 256 2^8个不同的字符编号从 0 到 255
- ISO 8859-1 的前 128 个字符与 ASCII 编码完全一致,这使得 ASCII 编码的文本可以无缝转换为 ISO 8859-1 编码。
![](./assets/38.gif)
![](./assets/41.gif)
![](./assets/39.gif)
![](./assets/42.gif)
- 计算机继续传播到了亚洲,亚洲(双字节)各个国家分别给出了自己国家对应的字符集编码,如:
- 日本推出了 Shift-JIS 编码:
@ -2277,7 +2284,7 @@ man ascii
- Unicode 仅仅只是字符集,给每个字符设置了唯一的数字编号而已,却没有给出这些数字编号实际如何存储,可以通过如下命令查看:
![](./assets/40.gif)
![](./assets/43.gif)
- 为了在计算机系统中表示 Unicode 字符,定义了几种编码方案,这些方案包括 UTF-8、UTF-16 和 UTF-32 等。
- **UTF-8**:使用 1 - 4 个字节表示每个 Unicode 字符,兼容 ASCII是网络上最常用的编码。
@ -2285,4 +2292,4 @@ man ascii
- **UTF-32**:使用固定的 4 个字节表示每个 Unicode 字符,简化了字符处理,但增加了存储空间的需求。
- `Unicode 字符集`和对应的`UTF-8 字符编码`之间的关系,如下所示:
![](./assets/41.png)
![](./assets/44.png)