diff options
| author | pjungeblut <paul.jungeblut@gmail.com> | 2014-11-25 22:54:57 +0100 |
|---|---|---|
| committer | pjungeblut <paul.jungeblut@gmail.com> | 2014-11-25 22:54:57 +0100 |
| commit | ac2c261f2c662f021c1016f18998a621c3ba0eaa (patch) | |
| tree | a839c7910c4abf1aa19d196fa6be885ca8d7432d /sonstiges | |
| parent | 3e4cca763aad161d84e524502605239487ccbf8e (diff) | |
bits
Diffstat (limited to 'sonstiges')
| -rw-r--r-- | sonstiges/bitOps.cpp | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/sonstiges/bitOps.cpp b/sonstiges/bitOps.cpp index 20ca532..b882965 100644 --- a/sonstiges/bitOps.cpp +++ b/sonstiges/bitOps.cpp @@ -1,22 +1,15 @@ -// [lsb: 0-th bit, msb: n-th bit,] - -//Get j-th bit: +//lsb: 0-th bit, msb: n-th bit +//get j-th bit (a & (1 << j)) != 0 - -//Set j-th bit: +//set j-th bit a |= (1 << j) - -//Clear j-th bit: +//clear j-th bit a &= ~(1 << j) - -//Toggle j-th bit: +//toggle j-th bit a ^= (1 << j) - -//Get value of first set bit: +//get value of least significant bit set (a & -a) - -//Turn on all bits: +//turn on all bits a = -1 - -//Turn on first n bits: +//turn on first n bits (be aware of overflows) a = (1 << n) - 1 |
