Update README.md

This commit is contained in:
marina 2023-08-07 22:37:51 -07:00 committed by GitHub
parent f2091f10d2
commit b6faf3956b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,29 @@
<br> <br>
### techniques
<br>
* test if kth bit is set: `num & (1 << k) != 0`
* set kth bit: `num |= (1 << k)`
* turn off kth bit: `num &= ~(1 << k)`
* toggle the kth bit: `num ^= (1 << k)`
* multiply by `2^k`: `num << k`
* dvide by `2^k`: `num >> k`
* check if a number is a power of 2: `(num & num - 1) == 0` or `(num & (-num)) == num`
* swapping two variables: `num1 ^= num2; num2 ^= num`; `num1 ^= num2`
<br>
--- ---