可以看出来,32位有符号整数可表示的最大数大于20亿,32位无符号整数可表示的最大数大于40亿,因此,碰上十几亿的海量数据处理时,不要慌~~
1 // 在32位系统中 2 // int的范围是[-2147483648,2147483647] 3 // unsigned int的范围是[0,4294967295] 4 const unsigned int min_uint = 0; 5 const unsigned int max_uint = 4294967295; 6 const int min_int = -(int)2147483648; 7 const int max_int = (int)2147483647; 8 9 // 将一个整数按2进制打印输出 10 inline void my_print_int(int n); 11 12 int main() 13 { 14 printf("MIN_UINT32=\t%u\n", (unsigned int)0); 15 16 // 32位全部置1,得到11111111111111111111111111111111 17 printf("MAX_UINT32=\t%u\n", (unsigned int)~(unsigned int)0); 18 printf("MAX_UINT32=\t%u\n", (unsigned int)0xFFFFFFFF); 19 20 // 将11111111111111111111111111111111右移一位,最左一位补0,得到01111111111111111111111111111111 21 // 符号位为0,其余为1 22 printf("MAX_INT32=\t%d\n", (int)(((unsigned int)~(unsigned int)0)>>1)); 23 printf("MAX_INT32=\t%d\n", (int)0x7FFFFFFF); 24 25 // 将01111111111111111111111111111111取反,得到10000000000000000000000000000000 26 // 将最大的正整数取反,得到最小的正整数 27 // 相当于最大的正整数取负,再减1 28 printf("MIN_INT32=\t%d\n", (int)~((int)(((unsigned int)~(unsigned int)0)>>1))); 29 printf("MIN_INT32=\t%d\n", -(int)1-((int)(((unsigned int)~(unsigned int)0)>>1))); 30 printf("MIN_INT32=\t%d\n", (int)0x80000000); 31 32 // 其它: 33 // ^是异或运算符 34 // 没有同或运算符 35 // 可以利用~和^,对异或的结果取反,从而构造同或运算, 36 int a = 0x657192A2; 37 int b = 0x5AF0A481; 38 int c = a^b; 39 int d = ~(a^b); 40 printf("A = \t"); 41 my_print_int(a); 42 printf("B = \t"); 43 my_print_int(b); 44 printf("异或\t"); 45 my_print_int(c); 46 printf("同或\t"); 47 my_print_int(d); 48 49 /* 输出结果为: 50 51 MIN_UINT32= 0 52 MAX_UINT32= 4294967295 53 MAX_UINT32= 4294967295 54 MAX_INT32= 2147483647 55 MAX_INT32= 2147483647 56 MIN_INT32= -2147483648 57 MIN_INT32= -2147483648 58 MIN_INT32= -2147483648 59 A = 01100101011100011001001010100010 60 B = 01011010111100001010010010000001 61 异或 00111111100000010011011000100011 62 同或 11000000011111101100100111011100 63 64 */ 65 66 getchar(); 67 return 0; 68 } 69 70 // 将一个整数按2进制打印输出 71 inline void my_print_int(int n) 72 { 73 char buff[33] = {0}; 74 for (int i = 0; i < 32; i++) 75 { 76 (n%2==0)?buff[31-i]='0':buff[31-i]='1'; 77 n>>=1; 78 } 79 printf("%s\n", buff); 80 }