Skip to content

Commit cdcd526

Browse files
committed
Update 01.Bit-Operation.md
1 parent f052f6a commit cdcd526

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Contents/09.Algorithm-Base/06.Bit-Operation/01.Bit-Operation.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
在学习二进制数的位运算之前,我们先来了解一下什么叫做「二进制数」。
88

9-
![](https://qcdn.itcharge.cn/images/20230225233101.png)
9+
![二进制数](https://qcdn.itcharge.cn/images/202405132135165.png)
1010

1111
> **二进制数(Binary)**:由 $0$ 和 $1$ 两个数码来表示的数。二进制数中每一个 $0$ 或每一个 $1$ 都称为一个「位(Bit)」。
1212
@@ -29,7 +29,7 @@
2929

3030
同理,在二进制数中,$01101010_{(2)}$ 可以看作为 $(0 \times 2^7) + (1 \times 2^6) + (1 \times 2^5) + (0 \times 2^4) + (1 \times 2^3) + (0 \times 2^2) + (1 \times 2^1) + (0 \times 2^0)$,即 $0 + 64 + 32 + 0 + 8 + 0 + 2 + 0 = 106_{(10)}$。
3131

32-
![](https://qcdn.itcharge.cn/images/20230225233152.png)
32+
![二进制数转十进制数](https://qcdn.itcharge.cn/images/202405132136456.png)
3333

3434
我们可以通过这样的方式,将一个二进制数转为十进制数。
3535

@@ -82,7 +82,7 @@ $\begin{aligned} 106 \div 2 = 53 & \text{(余 0)} \cr 53 \div 2 = 26 & \text
8282

8383
举个例子,对二进制数 $01111100_{(2)}$ 与 $00111110_{(2)}$ 进行按位与运算,结果为 $00111100_{(2)}$,如图所示:
8484

85-
![](https://qcdn.itcharge.cn/images/20230225233202.png)
85+
![按位与运算](https://qcdn.itcharge.cn/images/202405132137023.png)
8686

8787
### 2.2 按位或运算
8888

@@ -97,7 +97,7 @@ $\begin{aligned} 106 \div 2 = 53 & \text{(余 0)} \cr 53 \div 2 = 26 & \text
9797

9898
举个例子,对二进制数 $01001010_{(2)}$ 与 $01011011_{(2)}$ 进行按位或运算,结果为 $01011011_{(2)}$,如图所示:
9999

100-
![](https://qcdn.itcharge.cn/images/20230225233231.png)
100+
![按位或运算](https://qcdn.itcharge.cn/images/202405132137593.png)
101101

102102
### 2.3 按位异或运算
103103

@@ -115,7 +115,7 @@ $\begin{aligned} 106 \div 2 = 53 & \text{(余 0)} \cr 53 \div 2 = 26 & \text
115115

116116
举个例子,对二进制数 $01001010_{(2)}$ 与 $01000101_{(2)}$ 进行按位异或运算,结果为 $00001111_{(2)}$,如图所示:
117117

118-
![](https://qcdn.itcharge.cn/images/20230225233240.png)
118+
![按位异或运算](https://qcdn.itcharge.cn/images/202405132137874.png)
119119

120120
### 2.4 取反运算
121121

@@ -127,21 +127,21 @@ $\begin{aligned} 106 \div 2 = 53 & \text{(余 0)} \cr 53 \div 2 = 26 & \text
127127

128128
举个例子,对二进制数 $01101010_{(2)}$ 进行取反运算,结果如图所示:
129129

130-
![](https://qcdn.itcharge.cn/images/20230225233257.png)
130+
![取反运算](https://qcdn.itcharge.cn/images/202405132138853.png)
131131

132132
### 2.5 左移运算和右移运算
133133

134134
> **左移运算(SHL)**: 左移运算符为 `<<`。其功能是对一个二进制数的各个二进位全部左移若干位(高位丢弃,低位补 $0$)。
135135
136136
举个例子,对二进制数 $01101010_{(2)}$ 进行左移 $1$ 位运算,结果为 $11010100_{(2)}$,如图所示:
137137

138-
![](https://qcdn.itcharge.cn/images/20230225233308.png)
138+
![左移运算](https://qcdn.itcharge.cn/images/202405132138841.png)
139139

140140
> **右移运算(SHR)**: 右移运算符为 `>>`。其功能是对一个二进制数的各个二进位全部右移若干位(低位丢弃,高位补 $0$)。
141141
142142
举个例子,对二进制数 $01101010_{(2)}$ 进行右移 $1$ 位运算,结果为 $00110101_{(2)}$,如图所示:
143143

144-
![](https://qcdn.itcharge.cn/images/20230225233317.png)
144+
![右移运算](https://qcdn.itcharge.cn/images/202405132138348.png)
145145

146146
## 3. 位运算的应用
147147

0 commit comments

Comments
 (0)