-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from ajitonelsonn/dev
operasaun bitwise
- Loading branch information
Showing
3 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Operasaun bitwise | ||
|
||
Operasaun bitwise iha Python permite ita halo operasaun aaritmétika iha nível bit. Iha Python, ita bele uza operadores bitwise hanesan `&` (AND bit-a-bit), `|` (OR bit-a-bit), `^` (XOR bit-a-bit), `~` (NOT bit-a-bit), `<<` (Shift left), no `>>` (Shift right) atu manipula valores iha nível bit. | ||
|
||
Lista operadores bitwise sira: | ||
|
||
1. `&`: AND bit-a-bit. | ||
2. `|`: OR bit-a-bit. | ||
3. `^`: XOR bit-a-bit. | ||
4. `~`: NOT bit-a-bit. | ||
5. `<<`: Shift left. | ||
6. `>>`: Shift right. | ||
|
||
Ezemplu sira: | ||
|
||
```python | ||
# AND bit-a-bit | ||
print(5 & 3) # Sai 1 (101 & 011 = 001) | ||
|
||
# OR bit-a-bit | ||
print(5 | 3) # Sai 7 (101 | 011 = 111) | ||
|
||
# XOR bit-a-bit | ||
print(5 ^ 3) # Sai 6 (101 ^ 011 = 110) | ||
|
||
# NOT bit-a-bit | ||
print(~5) # Sai -6 (~101 = -110) | ||
|
||
# Shift left | ||
print(5 << 1) # Sai 10 (101 << 1 = 1010) | ||
|
||
# Shift right | ||
print(5 >> 1) # Sai 2 (101 >> 1 = 10) | ||
``` | ||
|
||
### BITWISE | ||
|
||
<img src='https://miro.medium.com/v2/resize:fit:1088/format:webp/1*xIxbMeCIPufBSCAEIKAG9A.png'> | ||
|
||
### EZAMPLE | ||
|
||
#### AND | ||
|
||
<img src='https://journaldev.nyc3.cdn.digitaloceanspaces.com/2019/02/python-bitwise-and-operator.png'> | ||
|
||
#### OR | ||
|
||
<img src='https://journaldev.nyc3.cdn.digitaloceanspaces.com/2019/02/python-bitwise-or-operator.png'> | ||
|
||
#### XOR | ||
|
||
<img src='https://journaldev.nyc3.cdn.digitaloceanspaces.com/2019/02/python-bitwise-xor-operator.png'> | ||
|
||
#### Bitwise Ones’ Complement Operator | ||
|
||
<img src='https://journaldev.nyc3.cdn.digitaloceanspaces.com/2019/02/python-bitwise-ones-complement-operator.png'> | ||
|
||
#### Shift Left | ||
|
||
<img src='https://journaldev.nyc3.cdn.digitaloceanspaces.com/2019/02/python-bitwise-left-shift-operator.png'> | ||
|
||
#### Shift Right | ||
|
||
<img src='https://journaldev.nyc3.cdn.digitaloceanspaces.com/2019/02/python-bitwise-right-shift-operator.png'> | ||
|
||
Referencia : https://www.digitalocean.com/community/tutorials/python-bitwise-operators |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
### Exerciciu I | ||
|
||
Klaru! Hau sei fó imi alguns exercísiu sira hodi pratika operadores bitwise iha Python: | ||
|
||
1. **Exercísiu 1**: Kalkula AND bit-a-bit entre númeru 10 no 7. | ||
|
||
```python | ||
resultado = 10 & 7 | ||
print("AND bit-a-bit entre 10 no 7:", resultado) | ||
``` | ||
|
||
2. **Exercísiu 2**: Kalkula OR bit-a-bit entre númeru 10 no 7. | ||
|
||
```python | ||
resultado = 10 | 7 | ||
print("OR bit-a-bit entre 10 no 7:", resultado) | ||
``` | ||
|
||
3. **Exercísiu 3**: Kalkula XOR bit-a-bit entre númeru 10 no 7. | ||
|
||
```python | ||
resultado = 10 ^ 7 | ||
print("XOR bit-a-bit entre 10 no 7:", resultado) | ||
``` | ||
|
||
4. **Exercísiu 4**: Kalkula NOT bit-a-bit ba númeru 10. | ||
|
||
```python | ||
resultado = ~10 | ||
print("NOT bit-a-bit ba 10:", resultado) | ||
``` | ||
|
||
5. **Exercísiu 5**: Shift left 2 posisaun ba númeru 10. | ||
|
||
```python | ||
resultado = 10 << 2 | ||
print("Shift left 2 posisaun ba 10:", resultado) | ||
``` | ||
|
||
6. **Exercísiu 6**: Shift right 2 posisaun ba númeru 10. | ||
|
||
```python | ||
resultado = 10 >> 2 | ||
print("Shift right 2 posisaun ba 10:", resultado) | ||
``` | ||
|
||
```python | ||
print(format(5 ^ 3, '08b')) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# AND bit-a-bit | ||
print(5 & 3) # Sai 1 (101 & 011 = 001) | ||
print(format(5 & 3, '08b')) | ||
|
||
# OR bit-a-bit | ||
print(5 | 3) # Sai 7 (101 | 011 = 111) | ||
print(format(5 | 3, '08b')) | ||
# XOR bit-a-bit | ||
print(5 ^ 3) # Sai 6 (101 ^ 011 = 110) | ||
print(format(5 ^ 3, '08b')) | ||
# NOT bit-a-bit | ||
print(~5) # Sai -6 (~101 = -110) | ||
print(format(~5, '08b')) | ||
# Shift left | ||
print(5 << 1) # Sai 10 (101 << 1 = 1010) | ||
print(format(5 << 1, '08b')) | ||
# Shift right | ||
print(5 >> 1) # Sai 2 (101 >> 1 = 10) | ||
print(format(5 >> 1, '08b')) |