部分内容来自
<<COMPUTER ORGANIZATION AND ARCHITECTURE-DESIGNING FOR PERFORMANCE>> by William Stallings
整数表示(Integer representation)
Sign-Magnitude Representation
符号-量级表示法
对于n位的数,最左边的一位代表符号位,接下来的n-1位代表量级( 绝对值大小)
The simplest form of representation that employs a sign bit is the sign-magnitude representation. In an n-bit word, the rightmost bits hold the magnitude of
the integer.
这种方法有几种缺陷。一种是加法与减法操作既要考虑符号又要考虑量级,另外0的表示有两种。
+0=00000000
-0=10000000
因此ALU里面几乎不会使用这种表示方法(符号-量级法)
二的补码表示 (Twos Complement Representation)
最左边一位也是符号位(0为正数,1为负数)
该表示中减法操作可以转化为加法操作
(Negation):
Take the Boolean complement of each bit of the corresponding positive number, then add 1 to the resulting bit pattern viewed
as an unsigned integer.
To subtract B from A, take the twos complement of B and addit to A.
比如A-B相当于A加上B的补码(B按位取反加1)
最高有效位(most significant bit)权重为-2^(n-1)
Negation(取反/取负):
1. Take the Boolean complement of each bit of the integer (including the sign bit).That is, set each 1 to 0 and each 0 to 1.
2. Treating the result as an unsigned binary integer, add 1.
总体思想便是按位取反加1
减法操作
比如
2-7
0010-0111
减法转化成加法
0111取(TWOs complement)按位取反加1结果为1001
0010+1001=1011=-5