diff --git a/contents/algorithms/binary.md b/contents/algorithms/binary.md index 741d8aa3..c11dd1f3 100644 --- a/contents/algorithms/binary.md +++ b/contents/algorithms/binary.md @@ -17,7 +17,7 @@ Some helpful utility snippets: - Set kth bit: `num |= (1 << k)`. - Turn off kth bit: `num &= ~(1 << k)`. - Toggle the kth bit: `num ^= (1 << k)`. -- To check if a number is a power of 2, `num & num - 1 == 0`. +- To check if a number is a power of 2, `(num & num - 1) == 0` or `(num & (-num)) == num`. ## Corner cases