Skip to content

Commit

Permalink
Merge pull request #70 from samlior/main
Browse files Browse the repository at this point in the history
Improve bitmap index
  • Loading branch information
Jeiwan authored Nov 14, 2023
2 parents c146f4c + 642f44d commit 3a4ad32
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions content/docs/milestone_2/tick-bitmap-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ After finding word and bit positions, we need to make a mask. A mask is a number
bit position of the tick. To find the mask, we simply calculate `2**bit_pos` (equivalent of `1 << bit_pos`):
```python
mask = 2**bit_pos # or 1 << bit_pos
print(bin(mask))
#0b10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
print(format(mask, '#0258b')) ↓ here
#0b0000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
```

Next, to flip a flag, we apply the mask to the tick's word via bitwise XOR:
```python
word = (2**256) - 1 # set word to all ones
print(bin(word ^ mask)) ↓ here
print(format(word ^ mask, '#0258b')) ↓ here
#0b1111111111111111111111111111111111111111111111111111111111111111111111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
```

Expand All @@ -116,8 +116,8 @@ You'll see that 184th bit (counting from the right starting at 0) has flipped to
If a bit is zero, it'll set it to 1:
```python
word = 0
print(bin(word ^ mask))
#0b10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
print(format(word ^ mask, '#0258b')) ↓ here
#0b0000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
```

### Finding Next Tick
Expand Down

0 comments on commit 3a4ad32

Please sign in to comment.