mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2026-03-21 04:35:20 +08:00
Update binary.md: Correct shift direction (#740)
This commit is contained in:
@@ -47,7 +47,7 @@ Some helpful utility snippets:
|
||||
| Technique | Code |
|
||||
| --- | --- |
|
||||
| Test k<sup>th</sup> bit is set | `num & (1 << k) != 0` |
|
||||
| Set k<sup>th</sup> bit | <code>num |= (1 >> k)</code> |
|
||||
| Set k<sup>th</sup> bit | <code>num |= (1 << k)</code> |
|
||||
| Turn off k<sup>th</sup> bit | `num &= ~(1 << k)` |
|
||||
| Toggle the k<sup>th</sup> bit | `num ^= (1 << k)` |
|
||||
| Multiply by 2<sup>k</sup> | `num << k` |
|
||||
|
||||
Reference in New Issue
Block a user