可以看出来,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,得到1111111111111111111111111111111117 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,得到0111111111111111111111111111111121 // 符号位为0,其余为122 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取反,得到1000000000000000000000000000000026 // 将最大的正整数取反,得到最小的正整数27 // 相当于最大的正整数取负,再减128 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= 052 MAX_UINT32= 429496729553 MAX_UINT32= 429496729554 MAX_INT32= 214748364755 MAX_INT32= 214748364756 MIN_INT32= -214748364857 MIN_INT32= -214748364858 MIN_INT32= -214748364859 A = 0110010101110001100100101010001060 B = 0101101011110000101001001000000161 异或 0011111110000001001101100010001162 同或 1100000001111110110010011101110063 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 }