one's complement & two's complement

一的补码与二的补码解析
本文介绍了计算机科学中的两种重要概念——一的补码与二的补码。一的补码用于表示正数等于原码,负数等于反码;二的补码则是通常所说的补码表示法。
一的补码(one's complement) 指的是:正数=原码,负数=反码
而二的补码(two's complement) 指的就是通常所指的补码
A Programmer's Perspective Most books on systems—computer architecture, compilers, operating systems, and networking—are written as if the reader were going to design and implement such a system. We call this the “builder's persepective.” We believe that students should first learn about systems in terms of how they affect the behavior and performance of their programs—a “programmer's perspective.” Here are some simple examples showing the contrast between the two perspectives: Computer Arithmetic Logic design and computer architecture courses describe how to implement fast and efficient arithmetic circuits. For programmers, what really matters is how the finite word sizes used to represent integer and floating point data determines what values can be represented and the behavior of different operations. For example, consider the following C function to compute the squares of 5, 50, 500, 5000, 50000, 500000, and 5000000: void show_squares() { int x; for (x = 5; x <= 5000000; x*=10) printf("x = %d x^2 = %d\n", x, x*x); } When compiled on most machines, this program produces the following values: x = 5 x^2 = 25 x = 50 x^2 = 2500 x = 500 x^2 = 250000 x = 5000 x^2 = 25000000 x = 50000 x^2 = -1794967296 x = 500000 x^2 = 891896832 x = 5000000 x^2 = -1004630016 The first four values are exactly what one would expect, but the last three seem quite peculiar. We even see that the “square” of a number can be negative! Since data type int uses a 32-bit, two's complement representation on most machines, programs cannot represent the value 2.5 X 109 as an int. In Chapter 2 we cover the two's complement number system used to represent integers on most computers and its mathematical properties. We also cover the IEEE floating point representation from a programmer's perspective.
最新发布
08-25
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值