summaryrefslogtreecommitdiff
path: root/sonstiges
diff options
context:
space:
mode:
authorJBatzill <batzilljohannes@gmail.com>2014-11-25 17:04:02 +0100
committerJBatzill <batzilljohannes@gmail.com>2014-11-25 17:04:02 +0100
commitef0ce890afa1517011859ebe8c240178fdd154ed (patch)
tree9817c01074949274da46bf038fb1cdc570be57c6 /sonstiges
parent741a7bcb9ed0fa5175adbb3bf98f53e31b27c09c (diff)
Create bitOps.cpp
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