summaryrefslogtreecommitdiff
path: root/sonstiges
diff options
context:
space:
mode:
Diffstat (limited to 'sonstiges')
-rw-r--r--sonstiges/bitOps.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/sonstiges/bitOps.cpp b/sonstiges/bitOps.cpp
new file mode 100644
index 0000000..df8cd8f
--- /dev/null
+++ b/sonstiges/bitOps.cpp
@@ -0,0 +1,22 @@
+[lsb: 0-th bit, msb: n-th bit,]
+
+Get j-th bit:
+(a & (1 << j)) != 0
+
+Set j-th bit:
+a |= (1 << j)
+
+Clear j-th bit:
+a &= ~(1 << j)
+
+Toggle j-th bit:
+a ^= (1 << j)
+
+Get value of first set bit:
+(a & -a)
+
+Turn on all bits:
+a = -1
+
+Turn on first n bits:
+a = (1 << n) - 1