1、机器数的表示与运算Representation and Operation of Machine Numbers21.Machine numbers Number in the computer is called the Machine Number Structure sign bit+true value“0”“1”The positive signThe negative sign3E.g.+52=+0110100=0 0110100-52=-0110100=1 0110100sign bitsign bittrue valuetrue value42.Representation o
2、f machine numbers Representation of machine numbers Original code Inverse code Complement5Original codeUse the most significant bit to represent the sign bit,the remaining bits to represent true value.“0”Positive 0“1”Negative 1AdvantageThe true value of the original code is equal to its numerical va
3、lue,which is easy to understand.DisadvantageIt is difficult to use the original code to do add and subtract operations in the computer0 in the original code,its representation is not unique6The original code of 0 the representation of 0 in 8 bits+0=0 0000000-0=1 00000000 has more than one representa
4、tion in original code7Inverse codeFor a machine numberX If X 0X original=X anti-If X 0 X anti-is based on its original code,the symbol bit is unchanged,and the remaining bits are reversed.8E.g.X=-52=-0110100Xoriginal=1 0110100Xanti-=1 10010119The inverse code of 0-0anti-=00000000-0anti-=111111110 ha
5、s more than one representation in inverse code10ComplementThe complement representation method If X 0X Complement=X anti=X original If X0 X Complement=X anti 111E.g X=-52=-0110100X original=10110100X anti-=11001011X Complement=X anti 1=1100110012The complement of 0=1 00000000 Complement codes is the
6、 commonly used codes in computer.+0complement=+0original=00000000-0 complement=-0 anti+1=11111111+1If the computer employed an 8-bit character code,the first bit is omitted133.Complement Arithmetic Operation Complement can convert the subtraction operation to addition operation Because:X+Y Complemen
7、t=X Complement Y ComplementX Y Complement=X+(Y)Complement=X Complement Y ComplementE.g 1.66-51=66+(-51)=15 Twos Complement arithmetic operation 14 66 Complement=66 original=01000010 51 original=10110011 51 Complement=11001101 66 Complement 51 Complement=00001111=15115E.g 2.If X=52=0110100,Y=116=1110
8、100,X+Y=?X original=10110100 XComplement=Xanti+1=11001100 Y Complement=Y original=01110100 X+Y Complement=X Complement Y Complement=11001100+01110100=01000000 X+Y=+1000000 In modern computer systems,when programming,negative numbers can be represented by-,which is converted to complement codes by the compiler.E.g.If input-3 Compiled code=FDH