diff options
| author | Paul Jungeblut <s_jungeb@i08pc54.atis-stud.uni-karlsruhe.de> | 2014-11-25 17:08:35 +0100 |
|---|---|---|
| committer | Paul Jungeblut <s_jungeb@i08pc54.atis-stud.uni-karlsruhe.de> | 2014-11-25 17:08:35 +0100 |
| commit | 24a946fdaeb0e5ceabf458007128df4fd4872733 (patch) | |
| tree | ed55b8ae16442411724672df3c32a341b203a07d /sonstiges/bitOps.cpp | |
| parent | 6c52da34e58b900b574b4a420f41dae44700b7b8 (diff) | |
| parent | 083aca7f730fec966e384f80a902b062f4c3b799 (diff) | |
Merge branch 'master' of https://github.com/pjungeblut/ChaosKITs
merge# Bitte geben Sie eine Commit-Beschreibung ein um zu erklären, warum dieser
Diffstat (limited to 'sonstiges/bitOps.cpp')
| -rw-r--r-- | sonstiges/bitOps.cpp | 22 |
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 |
