Two's complement

本文深入解析了计算机组织课程中提到的二进制补码概念,解释了如何通过翻转位元并加一来表示负数,以及为何这种表示方法使得整数运算在计算机中变得高效直接。文章引用了具体实例和算法书籍的解释,以清晰地阐述补码背后的数学逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值