随笔分类 - c++ learning
*位运算
摘要:1 // 判断一个数是否为2的n次幂 2 return !(a & (a-1)) 3 // 简单移位操作 4 a<<1 == a*2 5 a>>1 == a/2 6 // 异或操作<相同取反> 7 a^a==0 a^0==a 8 // 把右数第k位变成1 9 a | (1<<(k-1))10 // 把右数第k位变成011 a & (!(1<<(k-1)))12 // 第k位取反13 a ^ (1<<(k-1))判断一个数二进制中1的个数是奇数还是偶数:x = x ^ (x>>1); x = x
阅读全文
<String_>
摘要:string_ 1 /* 2 boring 3 eth0 4 */ 5 #ifndef SSTRING_H 6 #define SSTRING_H 7 8 9 #include <iostream> 10 #include <cstring> 11 #include <algorithm> 12 using std::istream; 13 using std::ostream; 14 15 class sstring 16 { 17 private: 18 friend istream& operator>>(istream&,
阅读全文
浙公网安备 33010602011771号