mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Update README.md
This commit is contained in:
parent
da47a56961
commit
913a26b906
@ -1,33 +1,5 @@
|
|||||||
## bit manipulation
|
## bit manipulation
|
||||||
|
|
||||||
<br>
|
|
||||||
|
|
||||||
### `playing_with_bits.py`
|
|
||||||
|
|
||||||
<br>
|
|
||||||
|
|
||||||
|
|
||||||
```python
|
|
||||||
> python3 playing_with_bits.py
|
|
||||||
|
|
||||||
Integer number: 144
|
|
||||||
Binary number: 10010000
|
|
||||||
|
|
||||||
Update bit: 0b10010100
|
|
||||||
Set bit: 0b10010100
|
|
||||||
Clear bit: 0b10000000
|
|
||||||
|
|
||||||
I: 144, I2: 90
|
|
||||||
B: 10010000, B2: 01011010
|
|
||||||
Count bits swapped: 4
|
|
||||||
|
|
||||||
Swap bit in place: (90, 144)
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
----
|
|
||||||
|
|
||||||
### bit manipulations
|
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
@ -134,4 +106,34 @@ Swap bit in place: (90, 144)
|
|||||||
* an integer of type int can be represented as a 32-bit binary number.
|
* an integer of type int can be represented as a 32-bit binary number.
|
||||||
* since a one-digit hexadecimal number corresponds to a four-digit binary number, an integer of type int can also be represented as an 8-bit hexadecimal number.
|
* since a one-digit hexadecimal number corresponds to a four-digit binary number, an integer of type int can also be represented as an 8-bit hexadecimal number.
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### examples
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
#### `playing_with_bits.py`
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
|
||||||
|
```python
|
||||||
|
> python3 playing_with_bits.py
|
||||||
|
|
||||||
|
Integer number: 144
|
||||||
|
Binary number: 10010000
|
||||||
|
|
||||||
|
Update bit: 0b10010100
|
||||||
|
Set bit: 0b10010100
|
||||||
|
Clear bit: 0b10000000
|
||||||
|
|
||||||
|
I: 144, I2: 90
|
||||||
|
B: 10010000, B2: 01011010
|
||||||
|
Count bits swapped: 4
|
||||||
|
|
||||||
|
Swap bit in place: (90, 144)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user