您的位置:首页 > 理论基础

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

2016-06-21 16:00 519 查看
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);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: