Two's complement
2012-06-07 10:45
211 查看
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.
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.
相关文章推荐
- Two's Complement
- 转载:整数二进制补码的数学原理(two's complement)
- one's-complement 反码, two's-complement 补码, one's complement sum, two's complement sum
- 整数二进制补码的数学原理(two's complement)
- one's complement & two's complement
- one's complement & two's complement【待考究】
- one's complement & two's complement
- 拥有进制转换(Two's complement,支持负数)功能的My Calculator 1.3完成啦!
- Two's Complement
- error: two or more data types in declaration of 'main'
- Educational Codeforces Round 2 D.Area of Two Circles' Intersection(计算几何)
- Educational Codeforces Round 2D. Area of Two Circles' Intersection(计算几何+圆相交的面积)
- two or more data types in declaration of `main'
- (转)A SQL query walks into a bar and sees two tables. He walks up to them and says 'Can I join you?'
- i am late ,when i feel i am late ,that is two o 'clock
- Educational Codeforces Round 2 D - Area of Two Circles' Intersection(两圆交面积)
- 【iOS】swift-Binary operator '|' cannot be applied to two UIViewAutoresizing operands
- two+or+more+data+types+in+declaration+of+`main'
- ones' complement 和 two's complement
- freetextbox 只能显示两张图片 user defined custom images (here, we're just allowing the first two)