嵌入式软件工程师&&太极拳
全部博文(548)
分类:
2011-02-20 20:06:20
#includeint main(void) { char a = 156; //a是1个字节; unsigned : 0 - 255; signed : -128 - 127; printf("a = %d \n", a); a = 256; //溢出; printf("a = %d \n", a); unsigned char c = 250; printf("c = %hhd \n", c); // ^ 打印1个字节; 是有符号数; printf以什么格式输出; int s = -1; printf("s = %u \n", s); // s = 4294967295 // ^ 无符号int; -1 ==> 对应的是最大的无符号数; // 负的2进制表示; -1 ==> 11111111 11111111 11111111 11111111 // 负数是以补码表示; ==> 00000000 00000000 00000000 00000000 + 1 // -2 ==> 00000000 00000000 00000000 00000010 - 1 // 00000000 00000000 00000000 00000001 // 11111111 11111111 11111111 11111110 s = -2; printf("s = %u \n", s); //s = 4294967294 unsigned int i ; i = 4294967295; printf("i = %u i + 1 = %u i + 2 = %u \n", i, i+1,i+2); short ss = 30567; printf("ss = %hd \n", ss); float ff = 0.2f; // printf("ff = %f \n", ff); //小数点后保留6位; // 1 (符号位) 8(指数位) 23(小数位) // 0 正 1 负 ; // 0.2 ==> 0.2 * 2 ==> 0.4 0 // 0.4 ==> 0.8 0 // 0.8 ==> 0.6 1 // 0.6 ==> 0.2 1 // ...................... ..0 // 0 // 1 // 1 //0.2 ==> 0.00110011001100110011.... //0.2 ==> 1.10011001100e-3 // 0 127-3=124 100110011001 // 0 01111100 1001100110011001100 double db = 1.23; // 1(符号位) 13(指数位) 50(小数) printf("db = %lf \n", db); int j = 96; printf("j = %d \n", j); printf("j = %#o \n", j); printf("j = %#x \n", j); // ^ 加前缀 ; 0 8进制; 0x 16进制; }