|
|
@ -47,7 +47,7 @@ Some helpful utility snippets:
|
|
|
|
| Technique | Code |
|
|
|
|
| Technique | Code |
|
|
|
|
| --- | --- |
|
|
|
|
| --- | --- |
|
|
|
|
| Test k<sup>th</sup> bit is set | `num & (1 << k) != 0` |
|
|
|
|
| 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)` |
|
|
|
|
| Turn off k<sup>th</sup> bit | `num &= ~(1 << k)` |
|
|
|
|
| Toggle the 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` |
|
|
|
|
| Multiply by 2<sup>k</sup> | `num << k` |
|
|
|
|