负数在计算机中存储方式,原码,补码,反码概念

 void test_1_2()

long x1 = 2169926;
long x2 = -2169926;
printf("x1 = %ld! x1 = 0x%08x x2 = %ld! x2 = 0x%08x\n", x1, x1, x2, x2);
long temp_l = 0;
long temp_l0 = 0;
long temp_l2 = 0;
long temp_l3 = 0;
long temp_l4 = 0;
long temp_l5 = 0;
temp_l = -x2;
printf("temp_l = %ld! temp_l = 0x%08x x2 = %ld! x2 = 0x%08x\n", temp_l, temp_l, x2, x2);
temp_l2 = temp_l | 0x80000000;
printf("temp_l2 = temp_l | 0x80000000; temp_l2 = %ld! temp_l2 = 0x%08x x2 = %ld! x2 = 0x%08x\n", temp_l2, temp_l2, x2, x2);
temp_l3 = ~temp_l2;
printf("temp_l3 = ~temp_l2; temp_l3 = %ld! temp_l3 = 0x%08x x2 = %ld! x2 = 0x%08x\n", temp_l3, temp_l3, x2, x2);
temp_l4 = temp_l3 | 0x80000000;
printf("temp_l4 = temp_l3 | 0x80000000; temp_l4 = %ld! temp_l4 = 0x%08x x2 = %ld! x2 = 0x%08x\n", temp_l4, temp_l4, x2, x2);
temp_l5 = temp_l4 + 1;// | 0x80000000;
printf("temp_l5 = temp_l4 + 1; temp_l5 = %ld! temp_l5 = 0x%08x x2 = %ld! x2 = 0x%08x\n*********************\n", temp_l5, temp_l5, x2, x2);


temp_l4 = temp_l5 - 1;
printf("temp_l4 = %ld! temp_l4 = 0x%08x x1 = %ld! x1 = 0x%08x\n", temp_l4, temp_l4, x1, x1);
temp_l3 = temp_l4 & (~0x80000000);
printf("temp_l3 = %ld! temp_l3 = 0x%08x x1 = %ld! x1 = 0x%08x\n", temp_l3, temp_l3, x1, x1);
temp_l2 = ~temp_l3;
printf("temp_l2 = %ld! temp_l2 = 0x%08x x1 = %ld! x1 = 0x%08x\n", temp_l3, temp_l3, x1, x1);
temp_l = temp_l2 & (~0x80000000);
printf("temp_l = %ld! temp_l = 0x%08x x1 = %ld! x1 = 0x%08x\n", temp_l, temp_l, x1, x1);

}

猜你喜欢

转载自blog.csdn.net/tankaro/article/details/51728034
今日推荐