Two's complement

I have learned two's complement in the computer organization course. At that time, I simply knew that to express a negative number, first find it's positive form, then flip every bit of it and finally add one on it. Although the specific steps are clear, I don't know the reason for it, in other words, I don't know why should I do this until I read an algorithm book which happens referred the two's complement.

The reason is this. For a n-bit long word, the all possible combination of numbers is 2n-1. Since we want to represent sign numbers, the range is (-2n-1 , 2n-1-1). Here’s a much simpler way to think about it: any number in this range is stored modulo 2n . Negative numbers −x therefore end up as 2n − x. Arithmetic operations like addition and subtraction can be performed directly in this format, ignoring any overflow bits that arise.

转载于:https://www.cnblogs.com/daizuozhuo/archive/2012/06/07/3052433.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值