c
Before Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 27 KiB |
4
docs/notes/01_c-basic/02_xdx/assets/19.svg
Normal file
After Width: | Height: | Size: 410 KiB |
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 483 KiB |
Before Width: | Height: | Size: 75 KiB After Width: | Height: | Size: 426 KiB |
Before Width: | Height: | Size: 88 KiB After Width: | Height: | Size: 495 KiB |
Before Width: | Height: | Size: 161 KiB After Width: | Height: | Size: 451 KiB |
Before Width: | Height: | Size: 118 KiB After Width: | Height: | Size: 522 KiB |
Before Width: | Height: | Size: 9.6 KiB After Width: | Height: | Size: 9.6 KiB |
Before Width: | Height: | Size: 172 KiB |
Before Width: | Height: | Size: 156 KiB After Width: | Height: | Size: 74 KiB |
Before Width: | Height: | Size: 188 KiB After Width: | Height: | Size: 75 KiB |
Before Width: | Height: | Size: 211 KiB After Width: | Height: | Size: 88 KiB |
Before Width: | Height: | Size: 253 KiB After Width: | Height: | Size: 161 KiB |
Before Width: | Height: | Size: 317 KiB After Width: | Height: | Size: 118 KiB |
Before Width: | Height: | Size: 253 KiB After Width: | Height: | Size: 172 KiB |
Before Width: | Height: | Size: 380 KiB After Width: | Height: | Size: 156 KiB |
Before Width: | Height: | Size: 398 KiB After Width: | Height: | Size: 188 KiB |
Before Width: | Height: | Size: 507 KiB After Width: | Height: | Size: 211 KiB |
Before Width: | Height: | Size: 534 KiB After Width: | Height: | Size: 253 KiB |
4
docs/notes/01_c-basic/02_xdx/assets/36.svg
Normal file
After Width: | Height: | Size: 317 KiB |
4
docs/notes/01_c-basic/02_xdx/assets/37.svg
Normal file
After Width: | Height: | Size: 253 KiB |
4
docs/notes/01_c-basic/02_xdx/assets/38.svg
Normal file
After Width: | Height: | Size: 380 KiB |
4
docs/notes/01_c-basic/02_xdx/assets/39.svg
Normal file
After Width: | Height: | Size: 398 KiB |
4
docs/notes/01_c-basic/02_xdx/assets/40.svg
Normal file
After Width: | Height: | Size: 507 KiB |
4
docs/notes/01_c-basic/02_xdx/assets/41.svg
Normal file
After Width: | Height: | Size: 534 KiB |
@ -815,7 +815,7 @@ int main() {
|
||||
|
||||
> [!NOTE]
|
||||
>
|
||||
> 在十六进制中,除了 0 到 9 这十个数字之外,还引入了字母,以便表示超过 9 的值。字母 A 对应十进制的 10 ,字母 B 对应十进制的 11 ,以此类推,字母 F 对应十进制的 15。
|
||||
> 在十六进制中,除了 `0` 到 `9` 这十个数字之外,还引入了字母,以便表示超过 `9` 的值。其中,字母 `A` 对应十进制的 `10` ,字母 `B` 对应十进制的 `11` ,字母 `C` 对应十进制的 `12`,字母 `D` 对应十进制的 `13`,字母 `E` 对应十进制的 `14`,字母 `F` 对应十进制的 `15`。
|
||||
|
||||
* 进制的换算举例,如下所示:
|
||||
|
||||
@ -963,6 +963,8 @@ int main() {
|
||||
|
||||
## 3.3 进制的运算规则
|
||||
|
||||
### 3.3.1 概述
|
||||
|
||||
* `十进制`的运算规则,如下所示:
|
||||
* 逢`十`进`一`(针对加法而言)。
|
||||
* 借`一`当`十`(针对减法而言)。
|
||||
@ -976,17 +978,47 @@ int main() {
|
||||
* 逢`十六`进`一`(针对加法而言)。
|
||||
* 借`一`当`十六`(针对减法而言)。
|
||||
|
||||
### 3.3.2 二进制的运算
|
||||
|
||||
* 二进制的加法:`1 + 0 = 1` 、`1 + 1 = 10`、`11 + 10 = 101`、`111 + 111 = 1110`。
|
||||
|
||||

|
||||
|
||||
* 二进制的减法:`1 - 0 = 1` 、`10 - 1 = 1`、`101 - 11 = 10`、`1100 - 111 = 101` 。
|
||||
|
||||

|
||||
|
||||
### 3.3.3 八进制的运算
|
||||
|
||||
* 八进制的加法:`3 + 4 = 7` 、`5 + 6 = 13`、`75 + 42 = 137`、`2427 + 567 = 3216`。
|
||||
|
||||

|
||||
|
||||
* 八进制的减法:`6 - 4 = 2` 、`52 - 27 = 33`、`307 - 141 = 146`、`7430 - 1451 = 5757` 。
|
||||
|
||||

|
||||
|
||||
### 3.3.4 十六进制的运算
|
||||
|
||||
* 十六进制的加法:`6 + 7 = D` 、`18 + BA = D2`、`595 + 792 = D27`、`2F87 + F8A = 3F11`。
|
||||
|
||||

|
||||
|
||||
* 十六进制的减法:`D - 3 = A` 、`52 - 2F = 23`、`E07 - 141 = CC6`、`7CA0 - 1CB1 = 5FEF` 。
|
||||
|
||||

|
||||
|
||||
## 3.4 进制的转换
|
||||
|
||||
### 3.4.1 概述
|
||||
|
||||
* 不同进制的转换,如下所示:
|
||||
|
||||

|
||||

|
||||
|
||||
* 在计算机中,数据是从右往左的方式排列的;其中,最右边的是低位,最左边的是高位,即:
|
||||
|
||||

|
||||

|
||||
|
||||
### 3.4.2 二进制和十进制的转换
|
||||
|
||||
@ -1003,13 +1035,13 @@ int main() {
|
||||
|
||||
* 示例:十进制转十进制
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
|
||||
* 示例:二进制转十进制
|
||||
|
||||

|
||||

|
||||
|
||||
#### 3.4.2.2 十进制转换二进制
|
||||
|
||||
@ -1025,13 +1057,13 @@ int main() {
|
||||
|
||||
* 示例:十进制转十进制
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
|
||||
* 示例:十进制转二进制
|
||||
|
||||

|
||||

|
||||
|
||||
### 3.4.3 二进制转八进制
|
||||
|
||||
@ -1041,7 +1073,7 @@ int main() {
|
||||
|
||||
* 示例:011 101 001 -> 351
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
|
||||
@ -1053,7 +1085,7 @@ int main() {
|
||||
|
||||
* 示例:1110 1001 -> 0xE9
|
||||
|
||||

|
||||

|
||||
|
||||
## 3.5 原码、反码和补码
|
||||
|
||||
@ -1065,7 +1097,7 @@ int main() {
|
||||
>
|
||||
> 这里讨论的适用于`符号位`的整数,如:int 等;而不适用于`无符号位`的整数,即:unsinged int 等。
|
||||
|
||||

|
||||

|
||||
|
||||
* 真值(数据位):因为机器数带有符号位,所以机器数的形式值不等于其真实表示的值(真值),以机器数 1000 0001 为例,其真正表示的值(首位是符号位)为 -1,而形式值却是 129 ,因此将带有符号位的机器数的真正表示的值称为机器数的真值。
|
||||
|
||||
@ -1073,7 +1105,7 @@ int main() {
|
||||
>
|
||||
> 这里讨论的适用于`符号位`的整数,如:int 等;而不适用于`无符号位`的整数,即:unsinged int 等。
|
||||
|
||||

|
||||

|
||||
|
||||
### 3.5.2 原码
|
||||
|
||||
@ -1146,11 +1178,11 @@ int main() {
|
||||
|
||||
* 如果 `0` ,按照 `+0` 的情况进行处理,如下所示:
|
||||
|
||||

|
||||

|
||||
|
||||
* 如果 `0` ,按照 `-0` 的情况进行处理,如下所示:
|
||||
|
||||

|
||||

|
||||
|
||||
> [!IMPORTANT]
|
||||
>
|
||||
@ -1183,7 +1215,7 @@ int main() {
|
||||
>
|
||||
> 直接使用原码表示整数,让符号位也参与运算,那么对于减法来说,结果显然是不正确的。
|
||||
|
||||

|
||||

|
||||
|
||||
* 于是,人们开始继续探索,不断试错,终于设计出了`反码`,如下所示:
|
||||
|
||||
@ -1191,7 +1223,7 @@ int main() {
|
||||
>
|
||||
> 直接使用反码表示整数,让符号位也参与运算,对于 6 +(-18)来说,结果貌似正确。
|
||||
|
||||

|
||||

|
||||
|
||||
* 如果我们将`被减数`和`减数`对调一下,即:计算 `18 - 6` 的结果,也就是 `18 +(-6)`的结果,继续采用`反码`来进行运算,如下所示:
|
||||
|
||||
@ -1200,15 +1232,15 @@ int main() {
|
||||
> * ① 6 - 18,即:6+(-18),如果采用`反码`计算,结果是正确的;但是,18 - 6,即:18 +(-6),如果采用`反码`计算,结果相差 1 。
|
||||
> * ② 可以推断:如果按照`反码`来计算,小数 - 大数,结果正确;而大数 - 小数,结果相差 1 。
|
||||
|
||||

|
||||

|
||||
|
||||
* 对于这个相差的 `1` 必须进行纠正,但是又不能影响`小数-大数`的结果。于是,人们又绞尽脑汁设计出了`补码`,给`反码`打了一个`“补丁”`,终于把相差的 `1` 给纠正过来了。那么,`6 - 18` 按照`补码`的运算过程,如下所示:
|
||||
|
||||

|
||||

|
||||
|
||||
* 那么,`18 - 6` 按照`补码`的运算过程,如下所示:
|
||||
|
||||

|
||||

|
||||
|
||||
> [!IMPORTANT]
|
||||
>
|
||||
|