将-130转换为16位二进制补码

时间:2020-05-15 06:13:39

标签: c memory binary hardware-programming

我知道(130)base10 = 10000010,

不确定其余的方法。

1 个答案:

答案 0 :(得分:0)

您想要的是complement(x)+ 1,基本上是一个异或和:

#include <stdio.h>

int main(void) 
{ 
    short mask = 0xFFFF; // 1111111111111111
    short data = 130;    // 0000000010000010
         // Complement      1111111101111101
         // Complement + 1  1111111101111110 = -130

    printf("%d\n", (mask ^ data) + 1);
    return 0;
}

输出:

-130
相关问题