From b6faf3956b99d614cd639625e7b2a5ebb695da0e Mon Sep 17 00:00:00 2001 From: marina <138340846+bt3gl-cryptographer@users.noreply.github.com> Date: Mon, 7 Aug 2023 22:37:51 -0700 Subject: [PATCH] Update README.md --- bit_operations/README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bit_operations/README.md b/bit_operations/README.md index 96cf3ad..6d32798 100644 --- a/bit_operations/README.md +++ b/bit_operations/README.md @@ -3,6 +3,29 @@
+### techniques + +
+ +* 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` + + + +
---