From 642f44d26d745bfbc3d38de159ec936c146193b9 Mon Sep 17 00:00:00 2001 From: samlior Date: Thu, 22 Jun 2023 18:00:03 +0800 Subject: [PATCH] Improve bitmap index --- content/docs/milestone_2/tick-bitmap-index.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/content/docs/milestone_2/tick-bitmap-index.md b/content/docs/milestone_2/tick-bitmap-index.md index 05e16942..b5d8f8b6 100644 --- a/content/docs/milestone_2/tick-bitmap-index.md +++ b/content/docs/milestone_2/tick-bitmap-index.md @@ -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 ``` @@ -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