What is “2's Complement”?

前端 未结 23 2476
名媛妹妹
名媛妹妹 2020-11-21 05:59

I\'m in a computer systems course and have been struggling, in part, with Two\'s Complement. I want to understand it but everything I\'ve read hasn\'t brought the p

23条回答
  •  旧巷少年郎
    2020-11-21 06:29

    Lets get the answer 10 – 12 in binary form using 8 bits: What we will really do is 10 + (-12)

    We need to get the compliment part of 12 to subtract it from 10. 12 in binary is 00001100. 10 in binary is 00001010.

    To get the compliment part of 12 we just reverse all the bits then add 1. 12 in binary reversed is 11110011. This is also the Inverse code (one's complement). Now we need to add one, which is now 11110100.

    So 11110100 is the compliment of 12! Easy when you think of it this way.

    Now you can solve the above question of 10 - 12 in binary form.

    00001010
    11110100
    -----------------
    11111110  
    

提交回复
热议问题