1 //5.13晚 位运算 2 3 1. int 类型最大值 4 5 int Getmaxint() 6 { 7 return (1<<31)-1;//2147483647 8 } 9 10 int Getmaxint() 11 { 12 return ~(1<<31); 13 } 14 15 2. int 所占字节 16 17 int Getzjint() 18 { 19 return ((unsigned int)-1)>>1;//-2147483648 20 } 21 22 3. n/2 23 24 n>>1; 25 26 4. n*2 27 28 n<<1; 29 30 5. n*(2^m) 31 32 n>>m; 33 34 6. n/(2*m) 35 36 n>>m; 37 38 7. swap(a,b) 39 40 a^=b; 41 b^=a; 42 a^=b; 43 44 8. 2^n 45 46 2<<(n-1);//最多算到2^30 47 48 9. 对2^n% 49 50 int m,int n, 51 2^n%m 52 53 m&(n-1);