Skip to content

Commit

Permalink
Improve bitmap index
Browse files Browse the repository at this point in the history
  • Loading branch information
samlior committed Jun 22, 2023
1 parent 15a4feb commit 642f44d
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 @@ -99,14 +99,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 @@ -115,8 +115,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 642f44d

Please sign in to comment.