Skip to content

Commit 6f00b4a

Browse files
djeadaCopilot
andauthored
Update notes/brain_teasers.md
Co-authored-by: Copilot <[email protected]>
1 parent 72e09b9 commit 6f00b4a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

notes/brain_teasers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,8 @@ This sequence of XOR operations swaps the values of `a` and `b` without needing
671671

672672
#### Bit Shifting Tricks
673673

674-
- *Left shifting* (`<<`) is a useful technique for *multiplying by powers of two*. For instance, `number << 3` multiplies `number` by $(2^3 = 8)$, which is a fast alternative to regular multiplication.
675-
- Similarly, *right shifting* (`>>`) can be used for *dividing by powers of two*. For example, `number >> 2` divides `number` by $(2^2 = 4)$, making it an efficient way to handle division for unsigned integers or logical shifts.
674+
- *Left shifting* (`<<`) is a useful technique for *multiplying by powers of two*. For instance, `number << 3` multiplies `number` by $2^3 = 8$, which is a fast alternative to regular multiplication.
675+
- Similarly, *right shifting* (`>>`) can be used for *dividing by powers of two*. For example, `number >> 2` divides `number` by $2^2 = 4$, making it an efficient way to handle division for unsigned integers or logical shifts.
676676
- To *extract specific bits* from a number, you can use a combination of shifting and masking. For instance, to extract bits from position $p$ to $p + n - 1$, the operation `(number >> p) & ((1 << n) - 1)` can be applied. This shifts the target bits to the right and uses a mask to isolate only those bits.
677677

678678
#### Cautions and Best Practices

0 commit comments

Comments
 (0)