How come in two's complementary, 1001 and 11111001 are both -7?

风流意气都作罢 提交于 2019-12-11 06:08:50

问题


When I learned two's complimentary, I was taught, that for a signed number,

0111 represents 7, so by using two's complementary,

0111 -> 1000 + 1 -> 1001, is -7

so 1001 represents -7.

While I refreshed this concept on YouTube, I see a video that is saying,

0000 0111 represents 7, so by using two's complementary,

0000 0111 -> 1111 1000 + 1 -> 1111 1001, is -7,

thus, 11111001 represents -7.

I got confused. So by just looking at a signed binary number, how can we determine its value? I thought 11111001 should equal to -121, since the first number MSB is 1, so it is negative, and 1111001 is -121 in decimal, so shouldn't 11111001 be -121? What did I do wrong?

Thanks guys!


回答1:


The only difference between the two examples is the number of bits you are using for each number.

1001 is -7 with 4 bits and 11111001 is -7 with 8 bits.

If you add up the negative and the positive of the same absolute number the result will be zero.

Both are -7 + 7 = 0

1001 + 0111 = 1|0000 

11111001 + 00000111 = 1|00000000 


来源:https://stackoverflow.com/questions/52394643/how-come-in-twos-complementary-1001-and-11111001-are-both-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!