Autosave: 2024-04-20 15:20:05
This commit is contained in:
parent
89633a997d
commit
4dcd427e38
2 changed files with 36 additions and 1 deletions
BIN
.zk/notebook.db
BIN
.zk/notebook.db
Binary file not shown.
|
@ -25,6 +25,41 @@ An example of using the `&` operator:
|
||||||
```py
|
```py
|
||||||
x = 5
|
x = 5
|
||||||
y = 3
|
y = 3
|
||||||
|
a = x & y
|
||||||
|
b = x | y
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The value of `a` will be 1. The reason is we are looking at the bit values of
|
||||||
|
`x` and `y` and then applying Boolean AND to each bit:
|
||||||
|
|
||||||
|
```
|
||||||
|
x = 5 = 0101
|
||||||
|
y = 3 = 0011
|
||||||
|
a = 1 = 0001
|
||||||
|
```
|
||||||
|
|
||||||
|
Working from right to left for each column:
|
||||||
|
|
||||||
|
- true and true = true
|
||||||
|
- false and true = false
|
||||||
|
- true and false = false
|
||||||
|
- false and false = false
|
||||||
|
|
||||||
|
This leaves us with 0001 which is equal to 1 in binary and denary.
|
||||||
|
|
||||||
|
For the case of bitwise OR we get 7 as the result of `x | y`:
|
||||||
|
|
||||||
|
```
|
||||||
|
x = 5 = 0101
|
||||||
|
y = 3 = 0011
|
||||||
|
b = 7 = 0111
|
||||||
|
```
|
||||||
|
|
||||||
|
- true or true = true
|
||||||
|
- false or true = true
|
||||||
|
- true or false = true
|
||||||
|
- false or false = true
|
||||||
|
|
||||||
|
This leaves us with 0111 which is equal to 7 in denary.
|
||||||
|
|
||||||
## Related notes
|
## Related notes
|
||||||
|
|
Loading…
Add table
Reference in a new issue