summaryrefslogtreecommitdiff
path: root/sonstiges/bitOps.cpp
blob: df8cd8f39c150380361f5869aae065d0199eccd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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