Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelliao authored Mar 7, 2025
1 parent 9f1ac13 commit b61fc7d
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ int d = n >>> 31; // 00000000 00000000 00000000 00000001 = 1

### 位运算

位运算是按位进行与、或、非和异或的运算。
位运算是按位进行与、或、非和异或的运算。我们先来看看针对单个bit的位运算。

与运算的规则是,必须两个数同时为`1`,结果才为`1`

Expand Down Expand Up @@ -181,14 +181,16 @@ n = 1 ^ 0; // 1
n = 1 ^ 1; // 0
```

对两个整数进行位运算,实际上就是按位对齐,然后依次对每一位进行运算。例如:
Java没有单个bit的数据类型。在Java中,对两个整数进行位运算,实际上就是按位对齐,然后依次对每一位进行运算。例如:

```java
// 位运算
public class Main {
public static void main(String[] args) {
int i = 167776589; // 00001010 00000000 00010001 01001101
int n = 167776512; // 00001010 00000000 00010001 00000000
// & -----------------------------------
// 00001010 00000000 00010001 00000000
System.out.println(i & n); // 167776512
}
}
Expand Down

0 comments on commit b61fc7d

Please sign in to comment.