summaryrefslogtreecommitdiff
path: root/sonstiges/bitOps.cpp
blob: b882965b51b74e90f7353b0e9a4ae19f7b8894fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//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 least significant bit set
(a & -a)
//turn on all bits
a = -1
//turn on first n bits (be aware of overflows)
a = (1 << n) - 1