diff options
Diffstat (limited to 'sonstiges')
| -rw-r--r-- | sonstiges/Roman.cpp | 18 | ||||
| -rw-r--r-- | sonstiges/bitOps.cpp | 16 |
2 files changed, 14 insertions, 20 deletions
diff --git a/sonstiges/Roman.cpp b/sonstiges/Roman.cpp index 195f833..c5ead54 100644 --- a/sonstiges/Roman.cpp +++ b/sonstiges/Roman.cpp @@ -24,17 +24,11 @@ string convertToRoman(int n) { n -= num[i]; } } - int pos = roman.find("CCCC"); - if(pos != string::npos) roman.replace(pos,4,"CD"); - pos = roman.find("XXXX"); - if(pos != string::npos) roman.replace(pos,4,"XL"); - pos = roman.find("IIII"); - if(pos != string::npos) roman.replace(pos,4,"IV"); - pos = roman.find("DCD"); - if(pos != string::npos) roman.replace(pos,3,"CM"); - pos = roman.find("LXL"); - if(pos != string::npos) roman.replace(pos,3,"XC"); - pos = roman.find("VIV"); - if(pos != string::npos) roman.replace(pos,3,"IX"); + int pos = roman.find("CCCC"); if(pos != string::npos) roman.replace(pos,4,"CD"); + pos = roman.find("XXXX"); if(pos != string::npos) roman.replace(pos,4,"XL"); + pos = roman.find("IIII"); if(pos != string::npos) roman.replace(pos,4,"IV"); + pos = roman.find("DCD"); if(pos != string::npos) roman.replace(pos,3,"CM"); + pos = roman.find("LXL"); if(pos != string::npos) roman.replace(pos,3,"XC"); + pos = roman.find("VIV"); if(pos != string::npos) roman.replace(pos,3,"IX"); return roman; } diff --git a/sonstiges/bitOps.cpp b/sonstiges/bitOps.cpp index df8cd8f..20ca532 100644 --- a/sonstiges/bitOps.cpp +++ b/sonstiges/bitOps.cpp @@ -1,22 +1,22 @@ -[lsb: 0-th bit, msb: n-th bit,] +// [lsb: 0-th bit, msb: n-th bit,] -Get j-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 first set bit: (a & -a) -Turn on all bits: +//Turn on all bits: a = -1 -Turn on first n bits: +//Turn on first n bits: a = (1 << n) - 1 |
